Skip to content

Class: RequestBatcher

A utility for batching a request

Constructors

constructor

new RequestBatcher(options?): RequestBatcher

Parameters

Name Type Description
options? Partial\<{ batchMillis: number }> options, including the value for batchMillis

Returns

RequestBatcher

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:83

Properties

batchMillis

batchMillis: number

The amount of time (in milliseconds) between requests of the same key

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:78


currentlyProcessing

Private currentlyProcessing: undefined | WaitingProcess\<any[], any> = undefined

A pointer to the current process the batcher is working on

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:67


lastRequestTimestampMap

Private lastRequestTimestampMap: Record\<string, number> = {}

A mapping between a process key and the last time in UTC a process of that key was executed.

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:62


processQueue

Private processQueue: WaitingProcess\<any[], any>[] = []

A queue of upcoming processes

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:73

Methods

isLoading

isLoading(key): boolean

Check if the request batcher is currently working on a process

Parameters

Name Type Description
key string the key of the process to check

Returns

boolean

true if the batcher is currently working on the provided process

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:96


queueProcess

queueProcess\<Args, ReturnType>(options): Promise\<ReturnType>

Adds a process to the queue and waits for the process to be complete

Type parameters

Name Type
Args extends any[]
ReturnType ReturnType

Parameters

Name Type Description
options WaitingProcessOptions\<Args, ReturnType> WaitingProcessOptions

Returns

Promise\<ReturnType>

A promise that resolves when the process resolves

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:161


triggerOrWaitProcess

triggerOrWaitProcess(): void

Triggers the next process in the queue or triggers a timeout to wait to execute the next process in the queue if not enough time has passed since the last process was triggered.

Returns

void

Defined in

packages/connected-solid/src/util/RequestBatcher.ts:106