-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process,worker: ensure code followed by exit() effectless
Cope with the delay(to the next function call) of v8::Isolate::TerminateExecution()
- Loading branch information
Showing
7 changed files
with
59 additions
and
5 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
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
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
18 changes: 18 additions & 0 deletions
18
test/parallel/test-worker-voluntarily-exit-followed-by-addition.js
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 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Worker, isMainThread } = require('worker_threads'); | ||
|
||
if (isMainThread) { | ||
const workerData = new Int32Array(new SharedArrayBuffer(4)); | ||
const w = new Worker(__filename, { | ||
workerData, | ||
}); | ||
w.on('exit', common.mustCall(() => { | ||
assert.strictEqual(workerData[0], 0); | ||
})); | ||
} else { | ||
const { workerData } = require('worker_threads'); | ||
process.exit(); | ||
workerData[0] = 1; | ||
} |
23 changes: 23 additions & 0 deletions
23
test/parallel/test-worker-voluntarily-exit-followed-by-throw.js
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,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Worker, isMainThread } = require('worker_threads'); | ||
|
||
if (isMainThread) { | ||
const workerData = new Int32Array(new SharedArrayBuffer(4)); | ||
const w = new Worker(__filename, { | ||
workerData, | ||
}); | ||
w.on('exit', common.mustCall(() => { | ||
assert.strictEqual(workerData[0], 0); | ||
})); | ||
} else { | ||
const { workerData } = require('worker_threads'); | ||
try { | ||
process.exit(); | ||
throw new Error('xxx'); | ||
// eslint-disable-next-line no-unused-vars | ||
} catch (err) { | ||
workerData[0] = 1; | ||
} | ||
} |