UNPKG

@push.rocks/smartproxy

Version:

A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.

29 lines (25 loc) 633 B
/** * Async concurrency semaphore — limits the number of concurrent async operations. */ export class ConcurrencySemaphore { private running = 0; private waitQueue: Array<() => void> = []; constructor(private readonly maxConcurrency: number) {} async acquire(): Promise<void> { if (this.running < this.maxConcurrency) { this.running++; return; } return new Promise<void>((resolve) => { this.waitQueue.push(() => { this.running++; resolve(); }); }); } release(): void { this.running--; const next = this.waitQueue.shift(); if (next) next(); } }