Node: Worker Threads: Add transferList to Worker constructor options

Created on 13 Mar 2020  路  1Comment  路  Source: nodejs/node

Is your feature request related to a problem? Please describe.

Based on the current documentation listed here, it doesn't seem possible to specify a transferList on the Worker constructor. This prohibits passing transferList items such as MessagePort. Attempts to pass a MessagePort within the Workers workerData currently results in the following error.

TypeError: MessagePort was found in message but not listed in transferList

Describe the solution you'd like

Given the current error, and if its technically feasible to do so...being able to supply a transferList on the Worker constructor would be helpful in initializing the Worker immediately with a MessagePort rather than sending the MessagePort on a subsequent postMessage(...). Perhaps something like the following could be allowed.

const channel = new MessageChannel()
const workerData = { port: channel.port1 }
const transferList = [channel.port1]
const worker = new Worker('./worker.js', { workerData, transferList  })

Describe alternatives you've considered

It is entirely possible to work around this by sending a MessagePort in a subsequent postMessage(..., transferList). However it doing so involves async initialization of the Worker which is less desirable than initializing immediately on the Worker constructor.

feature request good first issue mentor-available worker

Most helpful comment

can I work on this one?

>All comments

can I work on this one?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  3Comments

willnwhite picture willnwhite  路  3Comments

akdor1154 picture akdor1154  路  3Comments

srl295 picture srl295  路  3Comments

addaleax picture addaleax  路  3Comments