async pool returns result

This commit is contained in:
JOLIMAITRE Matthieu 2024-06-24 02:45:25 +02:00
parent 513e4d3f99
commit 0f5b0d18d8

View file

@ -9,11 +9,12 @@ export class AsyncPool {
this.limit = limit; this.limit = limit;
} }
async run(task: () => unknown) { async run<O>(task: () => Promise<O>) {
while (this.current >= this.limit) await this.current_changed.wait(); while (this.current >= this.limit) await this.current_changed.wait();
this.update_current(+1); this.update_current(+1);
await task(); const result = await task();
this.update_current(-1); this.update_current(-1);
return result;
} }
update_current(increment: number) { update_current(increment: number) {