Dev Guide
Dev GuideUser GuideGitHubNuGetDevCommunitySubmit a ticketLog In
GitHubNuGetDevCommunitySubmit a ticket

OCP App SDK / Batcher

Batcher<T>

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

Index

Constructors

Methods

Constructors

constructor()

Signature

new Batcher<T>(operation: BatchOperation<T>, limit: number = 100): Batcher<T>;

Type parameters

  • T

Parameters

NameTypeDefault value
operationBatchOperation<T>undefined
limitnumber100

Returns

Batcher<T>

Defined in: src/app/lib/Batcher.ts:15

Methods

append()

Append data to the batch, and if the batch size reaches the limit, perform and await the desired operation

Signature

append(data: T): Promise<void>;

Parameters

NameTypeDescription
dataTthe data needed by the operation. Of type T in new Batcher((data: T) => Promise)

Returns

Promise<void>

Defined in: src/app/lib/Batcher.ts:22

flush()

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.

Signature

flush(): Promise<void>;

Returns

Promise<void>

Defined in: src/app/lib/Batcher.ts:33