We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5b92eb4 commit 72f52a3Copy full SHA for 72f52a3
test/parallel/test-worker-exit-from-uncaught-exception.js
@@ -0,0 +1,23 @@
1
+'use strict';
2
+const common = require('../common');
3
+const assert = require('assert');
4
+const { Worker } = require('worker_threads');
5
+
6
+// Check that `process.exit()` can be called inside a Worker from an uncaught
7
+// exception handler.
8
9
+// Do not use isMainThread so that this test itself can be run inside a Worker.
10
+if (!process.env.HAS_STARTED_WORKER) {
11
+ process.env.HAS_STARTED_WORKER = 1;
12
+ const w = new Worker(__filename);
13
+ w.on('exit', common.mustCall((code) => {
14
+ assert.strictEqual(code, 42);
15
+ }));
16
+ return;
17
+}
18
19
+process.on('uncaughtException', () => {
20
+ process.exit(42);
21
+});
22
23
+throw new Error();
0 commit comments