import TinyPromiseQueue from './TinyPromiseQueue.mjs'; import TinyTimeout from '../math/TinyTimeout.mjs'; export type QueueResult = Promise; export type TinyThrottledApiEvents = { /** * - Emitted when a task starts executing. */ ExecTask: (id: string) => void; /** * - Emitted when a task finishes executing. */ TaskEnded: (id: string) => void; /** * - Emitted when a task is queued and waiting for a slot. */ WaitingTask: (id: string) => void; /** * - Emitted when the instance is destroyed. */ Destroyed: () => void; /** * - Emitted when the concurrency limit changes. */ SetConcurrencyLimit: (value: number) => void; /** * - Emitted when the timeout value changes. */ SetTimeoutValue: (value: number) => void; /** * - Emitted when the timeout limit changes. */ SetTimeoutLimit: (value: number) => void; }; /** * @template T * @typedef {Promise} QueueResult * Represents the eventual result of a queued operation. */ /** * Event map for {@link TinyThrottledApi}. * @typedef {Object} TinyThrottledApiEvents * @property {(id: string) => void} ExecTask - Emitted when a task starts executing. * @property {(id: string) => void} TaskEnded - Emitted when a task finishes executing. * @property {(id: string) => void} WaitingTask - Emitted when a task is queued and waiting for a slot. * @property {() => void} Destroyed - Emitted when the instance is destroyed. * @property {(value: number) => void} SetConcurrencyLimit - Emitted when the concurrency limit changes. * @property {(value: number) => void} SetTimeoutValue - Emitted when the timeout value changes. * @property {(value: number) => void} SetTimeoutLimit - Emitted when the timeout limit changes. */ /** @type {new () => import('../../jsdoc/EventEmitter.mjs').ICustomEventEmitter} */ declare const TypedEventEmitter: new () => import('../../jsdoc/EventEmitter.mjs').ICustomEventEmitter; /** * A client that manages asynchronous requests with a concurrency limit. * It uses TinyPromiseQueue to manage waiting tasks and waitForTrue to poll for availability. * @template {(...args: any) => Promise} API */ declare class TinyThrottledApi Promise> extends TypedEventEmitter { #private; static TinyTimeout: typeof TinyTimeout; /** * Initializes a new instance of the TinyThrottledApi class. * * @param {number} concurrencyLimit - The maximum number of simultaneous requests. * @param {API} api - The API implementation. * @param {TinyTimeout|null} [timeoutInstance=null] - Optional TinyTimeout instance to regulate execution frequency. * @throws {TypeError} If concurrencyLimit is not a positive number. * @throws {TypeError} If API is not a function. */ constructor(concurrencyLimit: number, api: API, timeoutInstance?: TinyTimeout | null); /** * Executes an API request, respecting the concurrency limit and optional rate limiting. * * @param {Parameters} args * @returns {QueueResult>} A promise that resolves with the API result. * @throws {TypeError} If the internal state is corrupted. */ exec(...args: Parameters): QueueResult>; /** * Cleans up the instance, removing all listeners and stopping pending tasks. * @returns {void} */ destroy(): void; /** * Returns whether the instance has been destroyed. * @returns {boolean} */ get isDestroyed(): boolean; /** * Gets the internal task queue. * @returns {TinyPromiseQueue} The internal task queue. */ get queue(): TinyPromiseQueue; /** * Gets the original API function. * @returns {API} The original API function. */ get api(): API; /** * Gets the current concurrency limit. * @returns {number} The current concurrency limit. */ get concurrencyLimit(): number; /** * Sets a new concurrency limit. * @param {number} value - The new maximum number of simultaneous requests. * @throws {TypeError} If value is not a positive number. */ set concurrencyLimit(value: number); /** * Gets the current TinyTimeout instance used for rate limiting. * @returns {TinyTimeout|null} */ get timeoutInstance(): TinyTimeout | null; /** * Gets the current base delay multiplier in milliseconds. * @returns {number} */ get timeoutValue(): number; /** * Sets a new base delay multiplier in milliseconds. * @param {number} value - The new base delay multiplier. * @throws {TypeError} If the value is not a number. * @throws {RangeError} If the value is a negative number. */ set timeoutValue(value: number); /** * Gets the current maximum delay cap. * @returns {number|null} */ get timeoutLimit(): number | null; /** * Gets whether the first execution should be delayed by the timeout. * @returns {boolean} */ get timeoutFirst(): boolean; /** * Sets whether the first execution should be delayed by the timeout. * @param {boolean} value - The new boolean value. * @throws {TypeError} If the value is not a boolean. */ set timeoutFirst(value: boolean); /** * Sets a new maximum delay cap. * @param {number} value - The new maximum delay cap. * @throws {TypeError} If the value is not a number. * @throws {RangeError} If the value is a negative number. */ set timeoutLimit(value: number); /** * Returns the number of currently active requests. * * @returns {number} */ get activeCount(): number; /** * Returns the number of tasks waiting in the queue. * * @returns {number} */ get queuedCount(): number; } export default TinyThrottledApi; //# sourceMappingURL=TinyThrottledApi.d.mts.map