From 252f5d8728cadb4d2ba35cb59b1bc3b52912002a Mon Sep 17 00:00:00 2001 From: Ranjan Purbey Date: Mon, 27 Apr 2020 04:13:57 +0530 Subject: [PATCH 1/2] doc: improve worker pool example In the worker pool example, the 'kWorkerFreedEvent' should be emitted in case of error as well. After adding new worker in the error handler, the pending tasks should be notified of an available worker. --- doc/api/async_hooks.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 5463c39bdc6c93..6c05a6928ed627 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -817,6 +817,7 @@ class WorkerPool extends EventEmitter { // current one. this.workers.splice(this.workers.indexOf(worker), 1); this.addNewWorker(); + this.emit(kWorkerFreedEvent); }); this.workers.push(worker); this.freeWorkers.push(worker); From 7d8cfe6664f709e86d1db73ff22d82230f473d2d Mon Sep 17 00:00:00 2001 From: Ranjan Purbey Date: Mon, 27 Apr 2020 04:48:14 +0530 Subject: [PATCH 2/2] doc: improve worker pool example emit kWorkerFreedEvent everytime a new worker is created --- doc/api/async_hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 6c05a6928ed627..0b1b22c82996f4 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -817,10 +817,10 @@ class WorkerPool extends EventEmitter { // current one. this.workers.splice(this.workers.indexOf(worker), 1); this.addNewWorker(); - this.emit(kWorkerFreedEvent); }); this.workers.push(worker); this.freeWorkers.push(worker); + this.emit(kWorkerFreedEvent); } runTask(task, callback) {