Skip to content

Commit

Permalink
use isMainThread
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonBall committed Jan 4, 2022
1 parent adcf374 commit b3d04ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Worker } from 'worker_threads';
import { Worker, isMainThread } from 'worker_threads';

// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
if (isMainThread) {
new Worker(new URL(import.meta.url));
await new Promise(() => {});
} else {
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/es-modules/tla/worker-process-exit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Worker, isMainThread } from 'worker_threads';

// Do not use isMainThread so that this test itself can be run inside a Worker.
if (isMainThread) {
new Worker(import.meta.url.slice('file://'.length));
await new Promise(() => {});
} else {
process.exit()
}

0 comments on commit b3d04ad

Please sign in to comment.