/** * Copyright 2025 Google LLC * * 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. */ /** * A handle to a promise and its resolvers. */ interface Task { resolve: (result: T) => void; reject: (err: unknown) => void; promise: Promise; } /** Utility for creating Tasks. */ declare function createTask(): Task; /** * A class designed to help turn repeated callbacks into async iterators. * Based loosely on a combination of Go channels and Promises. */ declare class Channel implements AsyncIterable { private ready; private buffer; private err; private done; send(value: T): void; close(): void; error(err: unknown): void; [Symbol.asyncIterator](): AsyncIterator; } /** * A lazy promise that does not run its executor function until then is called. */ declare class LazyPromise implements PromiseLike { private executor; private promise; constructor(executor: (resolve?: any, reject?: any) => void | Promise); then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseLike; } /** Lazily call the provided function to resolve the LazyPromise. */ declare function lazy(fn: () => T | PromiseLike): PromiseLike; /** * Options for AsyncTaskQueue. */ interface AsyncTaskQueueOptions { /** * If true, the queue will stop executing subsequent tasks if a task fails. * If false (default), the queue will continue executing subsequent tasks even if a task fails. */ stopOnError?: boolean; } /** * A queue for asynchronous tasks. The queue ensures that only one task runs at a time in order. */ declare class AsyncTaskQueue { private last; private options; constructor(options?: AsyncTaskQueueOptions); /** * Adds a task to the queue. * The task will be executed when its turn comes up in the queue. * @param task A function that returns a value or a PromiseLike. */ enqueue(task: () => any | PromiseLike): void; /** * Waits for all tasks currently in the queue to complete. */ merge(): Promise; } /** A lightweight, cross-platform EventEmitter. */ declare class EventEmitter { private listeners; on(event: string, listener: (...args: any[]) => void): void; off(event: string, listener: (...args: any[]) => void): void; emit(event: string, ...args: any[]): void; } export { AsyncTaskQueue, type AsyncTaskQueueOptions, Channel, EventEmitter, LazyPromise, type Task, createTask, lazy };