| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 79a277e commit fa77dc5
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -226,6 +226,8 @@ class Worker extends EventEmitter { | |||
| 226 | 226 | terminate(callback) { | |
| 227 | 227 | debug(`[${threadId}] terminates Worker with ID ${this.threadId}`); | |
| 228 | 228 | ||
| 229 | + this.ref(); | ||
| 230 | + | ||
| 229 | 231 | if (typeof callback === 'function') { | |
| 230 | 232 | process.emitWarning( | |
| 231 | 233 | 'Passing a callback to worker.terminate() is deprecated. ' + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const { once } = require('events'); | ||
| 4 | + const { Worker } = require('worker_threads'); | ||
| 5 | + | ||
| 6 | + // Test that calling worker.terminate() on an unref()’ed Worker instance | ||
| 7 | + // still resolves the returned Promise. | ||
| 8 | + | ||
| 9 | + async function test() { | ||
| 10 | + const worker = new Worker('setTimeout(() => {}, 1000000);', { eval: true }); | ||
| 11 | + await once(worker, 'online'); | ||
| 12 | + worker.unref(); | ||
| 13 | + await worker.terminate(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + test().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments