-
Notifications
You must be signed in to change notification settings - Fork 105
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
Feature: Interface Transferable / Piscina.move() #58
Comments
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, values returned by a worker are not transferable. That is, they will always be cloned because we currently have no way of telling Piscina that the value should be transferred instead.
My proposal is to add a new
Piscina.move()
function that takes an input object capable of being transferred and wraps it in a newTransferable
interface (in typescript terms) that effectively marks it as being able to be transferred.The return value of
move()
is aTransferable
, a wrapper object that (a) marks the object as being transferable and (b) provides a reference to the actual internal transferable object (e.g. the underlyingArrayBuffer
in the example above.This would only work with top level objects... for instance, the following would not cause the buffer to be transferred:
The
move()
function would work out of the box with objects known to be transferable by Node.js (e.g. MessagePorts and TypedArrays). Users would be able to create their own transferable objects by implementing theTransferable
interface on their classes.The text was updated successfully, but these errors were encountered: