Batcher
OCP App SDKOCP App SDK
OCP App SDKOCP App SDK / Batcher
Class: Batcher<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
Defined in: src/app/lib/Batcher.ts:15
Parameters
operation
`BatchOperation`BatchOperation<T>
limit
number = 100
Returns
Batcher<T>
Methods
append()
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()
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>