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

Transferable support #51

Open
qm3ster opened this issue Aug 25, 2018 · 6 comments
Open

Transferable support #51

qm3ster opened this issue Aug 25, 2018 · 6 comments

Comments

@qm3ster
Copy link

@qm3ster qm3ster commented Aug 25, 2018

Hi!
Do you think you could include a way to pass Transferable objects correctly?
It would be great to be able to return a MessagePort so that the function can return a stream instead of a single value.

@developit
Copy link
Owner

@developit developit commented Aug 26, 2018

Absolutely! We added it to greenlet in only a few bytes, the same solution should work reasonably well here. It would only auto-detect transferables passed directly as arguments, not within nested objects:

https://github.com/developit/greenlet/blob/master/greenlet.js#L25-L29

@cpoopc
Copy link

@cpoopc cpoopc commented Apr 7, 2019

look forward to it..

@NicolasRannou
Copy link

@NicolasRannou NicolasRannou commented Mar 24, 2020

Hi I'm a bit late to the party but it seems unclear to me... Are transferable objects supported by workerize or not?

@developit
Copy link
Owner

@developit developit commented May 7, 2020

They are not currently supported.

@shayke
Copy link

@shayke shayke commented May 18, 2020

Absolutely! We added it to greenlet in only a few bytes, the same solution should work reasonably well here. It would only auto-detect transferables passed directly as arguments, not within nested objects:

https://github.com/developit/greenlet/blob/master/greenlet.js#L25-L29

May I ask why only direct arguments? Why not detecting ArrayBuffers nested inside an object or an array?

@naoak
Copy link

@naoak naoak commented Dec 15, 2020

I was thinking of a way to specify a loader option for how to extract the transferable from the arguments and return value of a worker method, but I realized that it would be impossible to determine the best option for each worker method with just one loader option. Instead, the approach I took was to call setup functions on both the worker and the main thread side to determine how to extract the transferables for each worker method. I've made a helper module to achieve this.

https://github.com/naoak/workerize-transferable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.