Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worker Threads: Add transferList to Worker constructor options #32250

Closed
sinclairzx81 opened this issue Mar 13, 2020 · 1 comment
Closed

Worker Threads: Add transferList to Worker constructor options #32250

sinclairzx81 opened this issue Mar 13, 2020 · 1 comment
Labels
feature request Issues that request new features to be added to Node.js. good first issue Issues that are suitable for first-time contributors. worker Issues and PRs related to Worker support.

Comments

@sinclairzx81
Copy link

sinclairzx81 commented Mar 13, 2020

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.

@addaleax addaleax added feature request Issues that request new features to be added to Node.js. worker Issues and PRs related to Worker support. good first issue Issues that are suitable for first-time contributors. mentor-available labels Mar 13, 2020
@juanarbol
Copy link
Member

can I work on this one?

BethGriggs pushed a commit that referenced this issue Apr 7, 2020
PR-URL: #32278
Fixes: #32250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Apr 12, 2020
PR-URL: #32278
Fixes: #32250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit to targos/node that referenced this issue Apr 25, 2020
PR-URL: nodejs#32278
Fixes: nodejs#32250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Apr 28, 2020
PR-URL: #32278
Fixes: #32250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. good first issue Issues that are suitable for first-time contributors. worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants