-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for reloading module in multiple workers (#402)
* fix: use `NODE_MODULE_INIT` macro to improve worker support * test: add regression test * fix(test): skip test on windows, since it actually unloads the module (unlike linux) and segfaults
- Loading branch information
Showing
2 changed files
with
21 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { Worker } = require('worker_threads'); | ||
|
||
if (process.platform === 'win32') { | ||
// unloading the module segfaults on Windows, skip for now | ||
console.log('pass'); | ||
process.exit(); | ||
} | ||
|
||
(async function () { | ||
for (let i = 0; i < 2; i++) { | ||
const worker = new Worker("require('isolated-vm')", { eval: true }); | ||
await new Promise((resolve, reject) => { | ||
worker.on('exit', code => code ? reject(new Error(`Worker exited with code: ${code}`)) : resolve()); | ||
worker.on('error', error => reject(error)); | ||
}); | ||
} | ||
console.log('pass') | ||
})().catch(console.error); |