import EventEmitter from 'node:events'; import EmittingPromise, { CancelablePromise, Executor, FinallyFn, FulfillmentFn, RejectionFn } from './emitting-promise.js'; type SemaphoreEvents = { released: []; }; export type Semaphore = InstanceType; declare class SemaphoreImpl extends EventEmitter { #private; constructor(group: SemaphorePool, id: symbol); get id(): symbol; get released(): boolean; release(): Promise; } type PendingSemaphoreEvents = { reserved: [Semaphore]; error: [Error]; }; declare class PendingSemaphoreChain extends EmittingPromise implements CancelablePromise { #private; constructor(executor: Executor, parent?: SemaphorePromise); get pending(): boolean; then(onfulfilled?: FulfillmentFn, onrejected?: RejectionFn): PendingSemaphoreChain; catch(onrejected?: RejectionFn): PendingSemaphoreChain; finally(onfinally?: FinallyFn): PendingSemaphoreChain; cancel(): any; } export type SemaphoreRequest = InstanceType>; interface SemaphorePromise extends PendingSemaphoreChain { } declare class PendingSemaphore extends PendingSemaphoreChain { #private; constructor(timeoutMS?: number); resolve(semaphore: Semaphore): Promise; cancel(): Promise; reject(): Promise; } type SemaphorePoolEvents = { requested: [PendingSemaphore]; aborted: [PendingSemaphore, Error]; reserved: [Semaphore, PendingSemaphore]; released: [Semaphore]; }; export type SemaphorePoolConfig = { concurrency?: number; capacity?: number; }; export interface SemaphorePool extends EventEmitter { concurrency: number | undefined; capacity: number | undefined; reserved: number; queued: number; acquire(args?: { timeoutMS?: number; forOperation?: string; }): SemaphoreRequest; release(semaphore: Semaphore): void; } export declare class BasicSemaphorePool extends EventEmitter implements SemaphorePool { #private; constructor(config?: SemaphorePoolConfig); get queued(): number; get reserved(): number; get concurrency(): number | undefined; set concurrency(concurrency: number | undefined); get capacity(): number | undefined; set capacity(capacity: number | undefined); acquire(args?: { timeoutMS?: number; }): PendingSemaphoreChain; release(semaphore: Semaphore): void; } export {};