Skip to content

Commit e928902

Browse files
committed
use native Worker in Electron (fixes #29)
1 parent 21c8139 commit e928902

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/node/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Event(type, target) {
7272

7373
// this module is used self-referentially on both sides of the
7474
// thread boundary, but behaves differently in each context.
75-
export default threads.isMainThread ? mainThread() : workerThread();
75+
export default typeof Worker === 'function' ? Worker : threads.isMainThread ? mainThread() : workerThread();
7676

7777
const baseUrl = pathToFileURL(process.cwd() + '/');
7878

@@ -134,6 +134,10 @@ function mainThread() {
134134
}
135135

136136
function workerThread() {
137+
// loaded in a real Web Worker (eg: on Electron)
138+
if (typeof global.WorkerGlobalScope === 'function') {
139+
return;
140+
}
137141
let { mod, name, type } = threads.workerData;
138142
if (!mod) return mainThread();
139143

0 commit comments

Comments
 (0)