From 9edb9717ae4c1c86bd7d28553eaa1ef141fc133b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 15 Aug 2023 12:49:15 +0200 Subject: [PATCH] refactor: cleanup promise usage code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 2a52d548..f922aff5 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -555,7 +555,7 @@ export abstract class AbstractPool< } for (const [workerNodeKey, workerNode] of this.workerNodes.entries()) { workerNode.resetUsage() - this.sendWorkerStatisticsMessageToWorker(workerNodeKey) + this.sendStatisticsMessageToWorker(workerNodeKey) } } @@ -698,7 +698,7 @@ export abstract class AbstractPool< workerNodeKey: number, workerId: number ): Promise { - const waitForKillResponse = new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { this.registerWorkerMessageListener(workerNodeKey, (message) => { if (message.kill === 'success') { resolve() @@ -706,9 +706,8 @@ export abstract class AbstractPool< reject(new Error(`Worker ${workerId} kill message handling failed`)) } }) + this.sendToWorker(workerNodeKey, { kill: true, workerId }) }) - this.sendToWorker(workerNodeKey, { kill: true, workerId }) - await waitForKillResponse } /** @@ -999,8 +998,8 @@ export abstract class AbstractPool< this.registerWorkerMessageListener(workerNodeKey, this.workerListener()) // Send the startup message to worker. this.sendStartupMessageToWorker(workerNodeKey) - // Send the worker statistics message to worker. - this.sendWorkerStatisticsMessageToWorker(workerNodeKey) + // Send the statistics message to worker. + this.sendStatisticsMessageToWorker(workerNodeKey) } /** @@ -1011,11 +1010,11 @@ export abstract class AbstractPool< protected abstract sendStartupMessageToWorker (workerNodeKey: number): void /** - * Sends the worker statistics message to worker given its worker node key. + * Sends the statistics message to worker given its worker node key. * * @param workerNodeKey - The worker node key. */ - private sendWorkerStatisticsMessageToWorker (workerNodeKey: number): void { + private sendStatisticsMessageToWorker (workerNodeKey: number): void { this.sendToWorker(workerNodeKey, { statistics: { runTime: -- 2.34.1