Transferable.ts
Transferable.ts overview
Section titled “Transferable.ts overview”Marks encoded worker message fields that should move through postMessage as
transfer-list entries.
Worker messages still pass through schema encoding and structured clone, but
schemas wrapped with schema can also report backing resources such as
ArrayBuffer, ImageData.data.buffer, or MessagePort to a Collector.
Worker platforms then pass the collected values as the transfer list for the
same postMessage call, avoiding copies for large payloads and ports.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”accessors
Section titled “accessors”addAll
Section titled “addAll”Adds transferables to the current Collector when one is present in the
context, and does nothing otherwise.
Signature
declare const addAll: (tranferables: Iterable<globalThis.Transferable>) => Effect.Effect<void>Since v4.0.0
constructors
Section titled “constructors”makeCollector
Section titled “makeCollector”Effect that creates a fresh Collector service for accumulating
transferables.
Signature
declare const makeCollector: Effect.Effect< { readonly addAll: (_: Iterable<globalThis.Transferable>) => Effect.Effect<void> readonly addAllUnsafe: (_: Iterable<globalThis.Transferable>) => void readonly read: Effect.Effect<Array<globalThis.Transferable>> readonly readUnsafe: () => Array<globalThis.Transferable> readonly clearUnsafe: () => Array<globalThis.Transferable> readonly clear: Effect.Effect<Array<globalThis.Transferable>> }, never, never>Since v4.0.0
makeCollectorUnsafe
Section titled “makeCollectorUnsafe”Creates a mutable Collector service directly, exposing unsafe synchronous
methods for reading, adding, and clearing collected transferables.
Signature
declare const makeCollectorUnsafe: () => Collector["Service"]Since v4.0.0
getters
Section titled “getters”getterAddAll
Section titled “getterAddAll”Creates a schema getter that records transferables derived from a value in
the current Collector while passing the value through unchanged.
Signature
declare const getterAddAll: <A>(f: (_: A) => Iterable<globalThis.Transferable>) => SchemaGetter.Getter<A, A>Since v4.0.0
models
Section titled “models”Collector (class)
Section titled “Collector (class)”Service for collecting Transferable objects while encoding worker messages
so they can be passed to postMessage transfer lists.
Signature
declare class CollectorSince v4.0.0
schemas
Section titled “schemas”ImageData
Section titled “ImageData”Schema for transferring ImageData values with their pixel data buffer.
Signature
declare const ImageData: Transferable<Schema.declare<ImageData, ImageData>>Since v4.0.0
MessagePort
Section titled “MessagePort”Schema for transferring MessagePort values as transferable objects.
Signature
declare const MessagePort: Transferable<Schema.declare<MessagePort, MessagePort>>Since v4.0.0
Transferable (interface)
Section titled “Transferable (interface)”Schema wrapper whose encode path can record transferables with a Collector
while preserving the wrapped schema’s decoded type.
Signature
export interface Transferable<S extends Schema.Top> extends Schema.decodeTo< Schema.toType<S["Rebuild"]>, S["Rebuild"]> {}Since v4.0.0
Uint8Array
Section titled “Uint8Array”Schema for transferring Uint8Array values with their backing buffer.
Signature
declare const Uint8Array: Transferable<Schema.instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>Since v4.0.0
schema
Section titled “schema”Wraps a schema so encoding records transferables selected from the encoded
value, enabling worker messages to populate a postMessage transfer list.
Signature
declare const schema: { <S extends Schema.Top>(f: (_: S["Encoded"]) => Iterable<globalThis.Transferable>): (self: S) => Transferable<S> <S extends Schema.Top>(self: S, f: (_: S["Encoded"]) => Iterable<globalThis.Transferable>): Transferable<S>}Since v4.0.0