transfer(value) opts a clonable Transferable into move semantics: the value is added to the transfer list instead of being cloned, so ownership transfers to the peer and the value is detached locally.
Clonable Transferables (ArrayBuffer, typed-array views, ImageBitmap, VideoFrame, AudioData, …) are copied by structured clone by default. Wrapping one with transfer() moves it instead: the peer receives the original, and your local value is detached.
import {
consttransfer: <T>(value:T) =>T
Opt into transfer (move) semantics for a transferable value. Idempotent;
non-transferable inputs pass through unchanged. Silently degrades to a
copy when the platform/transport can't transfer the given type. Lies at
the type level - runtime value is a TransferWrapper typed as T.
Opt into transfer (move) semantics for a transferable value. Idempotent;
non-transferable inputs pass through unchanged. Silently degrades to a
copy when the platform/transport can't transfer the given type. Lies at
the type level - runtime value is a TransferWrapper typed as T.
transfer(
constbuffer:ArrayBuffer
buffer)) // buffer is detached locally
Moving large buffers avoids the copy entirely — see performance for when this matters.
ReadableStream and WritableStream are never transferred natively: their revivable modules claim them ahead of the transfer machinery and proxy them over a routed channel, chunk by chunk, on clone and JSON transports alike. Sending locks the source (a reader/writer is acquired) rather than detaching it, and transfer() is a no-op on them — see performance for the implications on large binary data. TransformStream has no proxy module, so it rides native structured-clone transfer (clone transports only).