Skip to content

Transferable.ts

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



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>

Source

Since v4.0.0

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
>

Source

Since v4.0.0

Creates a mutable Collector service directly, exposing unsafe synchronous methods for reading, adding, and clearing collected transferables.

Signature

declare const makeCollectorUnsafe: () => Collector["Service"]

Source

Since v4.0.0

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>

Source

Since v4.0.0

Service for collecting Transferable objects while encoding worker messages so they can be passed to postMessage transfer lists.

Signature

declare class Collector

Source

Since v4.0.0

Schema for transferring ImageData values with their pixel data buffer.

Signature

declare const ImageData: Transferable<Schema.declare<ImageData, ImageData>>

Source

Since v4.0.0

Schema for transferring MessagePort values as transferable objects.

Signature

declare const MessagePort: Transferable<Schema.declare<MessagePort, MessagePort>>

Source

Since v4.0.0

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"]
> {}

Source

Since v4.0.0

Schema for transferring Uint8Array values with their backing buffer.

Signature

declare const Uint8Array: Transferable<Schema.instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>

Source

Since v4.0.0

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>
}

Source

Since v4.0.0