Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
worker: make terminate() resolve for unref’ed Workers
Once `worker.terminate()` is called, the Worker instance will be destroyed as soon as possible anyway, so in order to make the Promise returned by `worker.terminate()` resolve always, it should be okay to just call `.ref()` on it and keep the main event loop alive temporarily. PR-URL: #29484 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
Showing
with
18 additions
and 0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @@ -0,0 +1,16 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const { once } = require('events'); | ||
| const { Worker } = require('worker_threads'); | ||
|
|
||
| // Test that calling worker.terminate() on an unref()’ed Worker instance | ||
| // still resolves the returned Promise. | ||
|
|
||
| async function test() { | ||
| const worker = new Worker('setTimeout(() => {}, 1000000);', { eval: true }); | ||
| await once(worker, 'online'); | ||
| worker.unref(); | ||
| await worker.terminate(); | ||
| } | ||
|
|
||
| test().then(common.mustCall()); |