Skip to content

Commit

Permalink
improve worker (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc authored Oct 30, 2023
1 parent 2e2ae49 commit 50bd4a1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/core/src/wasm-executor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ const logger = defaultLogger.child({ name: 'executor' })
let __executor_worker: Promise<{ remote: Comlink.Remote<WasmExecutor>; terminate: () => Promise<void> }> | undefined
const getWorker = async () => {
if (__executor_worker) return __executor_worker
if (typeof Worker !== 'undefined') {
__executor_worker = import('./browser-worker').then(({ startWorker }) => startWorker())
} else {

const isNode = typeof process !== 'undefined' && process?.versions?.node // true for node or bun

if (isNode) {
__executor_worker = import('./node-worker').then(({ startWorker }) => startWorker())
} else {
__executor_worker = import('./browser-worker').then(({ startWorker }) => startWorker())
}
return __executor_worker
}
Expand Down

0 comments on commit 50bd4a1

Please sign in to comment.