You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
module.exports=()=>{constbuf=Buffer.alloc(10);returnbuf;// Copies the buffer, rather than transferring it}
My proposal is to add a new Piscina.move() function that takes an input object capable of being transferred and wraps it in a new Transferable interface (in typescript terms) that effectively marks it as being able to be transferred.
The return value of move() is a Transferable, 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 underlying ArrayBuffer 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 the Transferable interface on their classes.
The text was updated successfully, but these errors were encountered:
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: