async pool returns result
This commit is contained in:
parent
513e4d3f99
commit
0f5b0d18d8
1 changed files with 3 additions and 2 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue