UNPKG

@firebase/firestore

Version:

This is the [Cloud Firestore](https://firebase.google.com/docs/firestore/) component of the [Firebase JS SDK](https://www.npmjs.com/package/firebase).

134 lines (133 loc) 5.75 kB
/** * @license * Copyright 2017 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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", /** * A timer used to retry transactions. Since there can be multiple concurrent * transactions, multiple of these may be in the queue at a given time. */ RetryTransaction = "retry_transaction" } export declare class AsyncQueue { private tail; private _isShuttingDown; private delayedOperations; failure: Error | null; private operationInProgress; private timerIdsToSkip; get isShuttingDown(): boolean; /** * Adds a new operation to the queue without waiting for it to complete (i.e. * we ignore the Promise result). */ enqueueAndForget<T extends unknown>(op: () => Promise<T>): void; /** * Regardless if the queue has initialized shutdown, adds a new operation to the * queue without waiting for it to complete (i.e. we ignore the Promise result). */ enqueueAndForgetEvenAfterShutdown<T extends unknown>(op: () => Promise<T>): void; /** * Regardless if the queue has initialized shutdown, adds a new operation to the * queue. */ private enqueueEvenAfterShutdown; /** * Adds a new operation to the queue and initialize the shut down of this queue. * Returns a promise that will be resolved when the promise returned by the new * operation is (with its value). * Once this method is called, the only possible way to request running an operation * is through `enqueueAndForgetEvenAfterShutdown`. */ enqueueAndInitiateShutdown(op: () => Promise<void>): 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<T extends unknown>(op: () => Promise<T>): Promise<T>; private enqueueInternal; /** * 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<T extends unknown>(timerId: TimerId, delayMs: number, op: () => Promise<T>): CancelablePromise<T>; 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<void>; /** * 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<void>; /** * For Tests: Skip all subsequent delays for a timer id. */ skipDelaysForTimerId(timerId: TimerId): void; /** Called once a DelayedOperation is run or canceled. */ private removeDelayedOperation; }