Skip to content

Commit

Permalink
fix(node-runtime-worker-thread): Read worker source and eval instead …
Browse files Browse the repository at this point in the history
…of passing path to the worker constructor (#679)

This fixes an issue of using the worker from electron asar bundle that doesn't allow worker to resolve the path
correctly.
  • Loading branch information
gribnoysup authored Feb 24, 2021
1 parent 3557e73 commit df0e331
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
*/
import { once } from 'events';
import { SHARE_ENV, Worker } from 'worker_threads';
import fs from 'fs';
import path from 'path';
import { exposeAll, createCaller } from './rpc';
import { InterruptHandle, interrupt as nativeInterrupt } from 'interruptor';

const workerRuntimeSrcPath = path.resolve(__dirname, 'worker-runtime.js');

const workerProcess = new Worker(workerRuntimeSrcPath, { env: SHARE_ENV });
const workerProcess = new Worker(
// It's fine in this use-case: this process is spawned so we are not blocking
// anything in the main process
// eslint-disable-next-line no-sync
fs.readFileSync(workerRuntimeSrcPath, 'utf8'),
{ env: SHARE_ENV, eval: true }
);

// We expect the amount of listeners to be more than the default value of 10 but
// probably not more than ~25 (all exposed methods on
Expand Down

0 comments on commit df0e331

Please sign in to comment.