From 0f5b0d18d8929ad5872c0e09f88e2be64d9fd3b9 Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Mon, 24 Jun 2024 02:45:25 +0200 Subject: [PATCH] async pool returns result --- src/lib/AsyncPool.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/AsyncPool.ts b/src/lib/AsyncPool.ts index 63814d4..22ed150 100644 --- a/src/lib/AsyncPool.ts +++ b/src/lib/AsyncPool.ts @@ -9,11 +9,12 @@ export class AsyncPool { this.limit = limit; } - async run(task: () => unknown) { + async run(task: () => Promise) { while (this.current >= this.limit) await this.current_changed.wait(); this.update_current(+1); - await task(); + const result = await task(); this.update_current(-1); + return result; } update_current(increment: number) {