feat(smart-proxy): add background concurrent certificate provisioning with per-domain timeouts and concurrency control
This commit is contained in:
28
ts/proxies/smart-proxy/utils/concurrency-semaphore.ts
Normal file
28
ts/proxies/smart-proxy/utils/concurrency-semaphore.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user