@itwin/core-bentley
Version:
Bentley JavaScript core components
32 lines • 1.72 kB
TypeScript
/** @packageDocumentation
* @module Utils
*/
/** @beta */
export declare class AbandonedError extends Error {
}
/**
* Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate
* the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP
* request queue to grow such that the delay to service new requests is unbounded.
*
* With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent
* requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.
* When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type
* of operation, but the first and last request will always eventually complete.
* @beta
*/
export declare class OneAtATimeAction<T> {
private _active?;
private _pending?;
private _run;
msg: string;
/** Ctor for OneAtATimePromise.
* @param run The method that performs an action that creates the Promise.
*/
constructor(run: (...args: any[]) => Promise<T>, msg?: string);
/** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.
* @note Callers of this method *must* handle AbandonedError rejections.
*/
request(...args: any[]): Promise<T>;
}
//# sourceMappingURL=OneAtATimeAction.d.ts.map