Skip to content

Commit

Permalink
feat: add custom transferList support (#142)
Browse files Browse the repository at this point in the history
close #131
  • Loading branch information
JounQin committed Dec 1, 2023
1 parent 363ee7d commit 097e5cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-olives-obey.md
@@ -0,0 +1,5 @@
---
"synckit": patch
---

feat: add custom transferList support
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Node.js LTS
uses: actions/setup-node@v4
with:
node-version: --lts
node-version: lts
cache: yarn

- name: Install Dependencies
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Expand Up @@ -4,11 +4,12 @@ import path from 'node:path'
import { pathToFileURL } from 'node:url'
import {
MessageChannel,
TransferListItem,
Worker,
parentPort,
receiveMessageOnPort,
// type-coverage:ignore-next-line -- we can't control
workerData,
parentPort,
} from 'node:worker_threads'

import { findUp, isPkgAvailable, tryExtensions } from '@pkgr/utils'
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface SynckitOptions {
timeout?: number
execArgv?: string[]
tsRunner?: TsRunner
transferList?: TransferListItem[]
}

// MessagePort doesn't copy the properties of Error objects. We still want
Expand Down Expand Up @@ -284,6 +286,7 @@ function startWorkerThread<R, T extends AnyAsyncFn<R>>(
timeout = DEFAULT_TIMEOUT,
execArgv = DEFAULT_EXEC_ARGV,
tsRunner = DEFAULT_TS_RUNNER,
transferList = [],
}: SynckitOptions = {},
) {
const { port1: mainPort, port2: workerPort } = new MessageChannel()
Expand Down Expand Up @@ -340,7 +343,7 @@ function startWorkerThread<R, T extends AnyAsyncFn<R>>(
{
eval: useEval,
workerData: { workerPort },
transferList: [workerPort],
transferList: [workerPort, ...transferList],
execArgv: finalExecArgv,
},
)
Expand Down

0 comments on commit 097e5cd

Please sign in to comment.