Skip to content

Commit

Permalink
avoid using isMainThread, since it interacts poorly with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Harris committed May 16, 2023
1 parent 2e6da94 commit abf6260
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/kit/src/utils/fork.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'node:url';
import { Worker, isMainThread, parentPort } from 'node:worker_threads';
import { Worker, parentPort } from 'node:worker_threads';

/**
* Runs a task in a subprocess so any dangling stuff gets killed upon completion.
Expand All @@ -11,7 +11,7 @@ import { Worker, isMainThread, parentPort } from 'node:worker_threads';
* @returns {(opts: T) => Promise<U>} A function that when called starts the subprocess
*/
export function forked(module, callback) {
if (!isMainThread && parentPort) {
if (process.env.SVELTEKIT_FORK && parentPort) {
parentPort.on(
'message',
/** @param {any} data */ async (data) => {
Expand All @@ -36,7 +36,8 @@ export function forked(module, callback) {
return new Promise((fulfil, reject) => {
const worker = new Worker(fileURLToPath(module), {
env: {
...process.env
...process.env,
SVELTEKIT_FORK: 'true'
}
});

Expand Down

0 comments on commit abf6260

Please sign in to comment.