Batcher
OCP App SDK / Batcher
Class: Batcher<T>
<T>
Defined in: src/app/lib/Batcher.ts:13
A class to aid in batching operations, such as sending requests to ODP APIs.
Usage
const eventBatcher = new Batcher(z.event);
...
await eventBatcher.append({type: 'pageview', {page: 'https://foo'});
...
await eventBatcher.flush();
Type Parameters
T
T
Constructors
Constructor
new Batcher
<T>
(operation
,limit
):Batcher<T>
Defined in: src/app/lib/Batcher.ts:15
Parameters
operation
limit
number
= 100
Returns
Batcher<T>
Methods
append()
append(
data
):Promise<void>
Defined in: src/app/lib/Batcher.ts:22
Append data to the batch, and if the batch size reaches the limit, perform and await the desired operation
Parameters
data
T
the data needed by the operation. Of type T in new Batcher<T>
((data: T) => Promise<void>
)
Returns
Promise``<void>
flush()
flush():
Promise``<void>
Defined in: src/app/lib/Batcher.ts:33
Flush any remaining items in the batcher. Do this before giving up control of your task, e.g., before exiting a job's perform method to make sure nothing is lost if the job needs to be paused and resumed.
Returns
Promise``<void>
Updated 10 days ago