import { Unknown } from './misc'; import { CancelablePromise } from './promise'; /** * Wellknown "timer" IDs used when scheduling delayed operations on the * AsyncQueue. These IDs can then be used from tests to check for the presence * of operations or to run them early. * * The string values are used when encoding these timer IDs in JSON spec tests. */ export declare enum TimerId { /** All can be used with runDelayedOperationsEarly() to run all timers. */ All = "all", /** * The following 4 timers are used in persistent_stream.ts for the listen and * write streams. The "Idle" timer is used to close the stream due to * inactivity. The "ConnectionBackoff" timer is used to restart a stream once * the appropriate backoff delay has elapsed. */ ListenStreamIdle = "listen_stream_idle", ListenStreamConnectionBackoff = "listen_stream_connection_backoff", WriteStreamIdle = "write_stream_idle", WriteStreamConnectionBackoff = "write_stream_connection_backoff", /** * A timer used in online_state_tracker.ts to transition from * OnlineState.Unknown to Offline after a set timeout, rather than waiting * indefinitely for success or failure. */ OnlineStateTimeout = "online_state_timeout", /** * A timer used to update the client metadata in IndexedDb, which is used * to determine the primary leaseholder. */ ClientMetadataRefresh = "client_metadata_refresh", /** A timer used to periodically attempt LRU Garbage collection */ LruGarbageCollection = "lru_garbage_collection", } export declare class AsyncQueue { private tail; private delayedOperations; failure: Error; private operationInProgress; /** * Adds a new operation to the queue without waiting for it to complete (i.e. * we ignore the Promise result). */ enqueueAndForget(op: () => Promise): void; /** * Adds a new operation to the queue. Returns a promise that will be resolved * when the promise returned by the new operation is (with its value). */ enqueue(op: () => Promise): Promise; /** * Schedules an operation to be queued on the AsyncQueue once the specified * `delayMs` has elapsed. The returned CancelablePromise can be used to cancel * the operation prior to its running. */ enqueueAfterDelay(timerId: TimerId, delayMs: number, op: () => Promise): CancelablePromise; private verifyNotFailed(); /** * Verifies there's an operation currently in-progress on the AsyncQueue. * Unfortunately we can't verify that the running code is in the promise chain * of that operation, so this isn't a foolproof check, but it should be enough * to catch some bugs. */ verifyOperationInProgress(): void; /** * Waits until all currently queued tasks are finished executing. Delayed * operations are not run. */ drain(): Promise; /** * For Tests: Determine if a delayed operation with a particular TimerId * exists. */ containsDelayedOperation(timerId: TimerId): boolean; /** * For Tests: Runs some or all delayed operations early. * * @param lastTimerId Delayed operations up to and including this TimerId will * be drained. Throws if no such operation exists. Pass TimerId.All to run * all delayed operations. * @returns a Promise that resolves once all operations have been run. */ runDelayedOperationsEarly(lastTimerId: TimerId): Promise; /** Called once a DelayedOperation is run or canceled. */ private removeDelayedOperation(op); }