Skip to content

Commit 4b6dac4

Browse files
fix: explicitly start MessagePort (#116)
Co-authored-by: Ari Perkkiö <[email protected]>
1 parent 5db47ee commit 4b6dac4

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/entry/worker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ parentPort!.on('message', (message: StartupMessage) => {
4949
const readyMessage: ReadyMessage = { ready: true }
5050
parentPort!.postMessage(readyMessage)
5151

52+
port.start()
53+
5254
port.on('message', onMessage.bind(null, port, sharedBuffer))
5355
atomicsWaitLoop(port, sharedBuffer)
5456
})().catch(throwInNextTick)

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ class ThreadPool {
791791

792792
worker.on('message', (message: ReadyMessage) => {
793793
if (message.ready === true) {
794+
port1.start()
795+
794796
if (workerInfo.currentUsage() === 0) {
795797
workerInfo.unref()
796798
}

src/runtime/process-worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default class ProcessWorker implements TinypoolWorker {
9292
transferListItem?.forEach((item) => {
9393
if (item instanceof MessagePort) {
9494
this.port = item
95+
this.port.start()
9596
}
9697
})
9798

@@ -149,7 +150,7 @@ export default class ProcessWorker implements TinypoolWorker {
149150

150151
// The forked child_process adds event listener on `process.on('message)`.
151152
// This requires manual unreffing of its channel.
152-
this.process.channel?.unref()
153+
this.process.channel?.unref?.()
153154

154155
if (hasUnref(this.process.stdout)) {
155156
this.process.stdout.unref()

0 commit comments

Comments
 (0)