RpcWorker.ts
RpcWorker.ts overview
Section titled “RpcWorker.ts overview”Initial messages for worker-backed RPC protocols.
A worker-backed RPC client can send one schema-encoded value before normal RPC
requests are handled. This module defines the InitialMessage service, a
helper for encoding that value while collecting transferables, a layer for
providing it to the client protocol, and a decoder for reading it from the
worker server protocol.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”initial message
Section titled “initial message”InitialMessage (class)
Section titled “InitialMessage (class)”Context service that supplies the initial RPC worker message as encoded data paired with any transferables that should be posted with it.
Signature
declare class InitialMessageSince v4.0.0
initialMessage
Section titled “initialMessage”Reads the protocol initial message and decodes it with the supplied schema, failing if no initial message is available or decoding fails.
Signature
declare const initialMessage: <S extends Schema.Constraint>( schema: S) => Effect.Effect<S["Type"], NoSuchElementError | Schema.SchemaError, Protocol | S["DecodingServices"]>Since v4.0.0
layerInitialMessage
Section titled “layerInitialMessage”Provides the InitialMessage service from a schema and build effect,
capturing the layer context and dying if schema encoding fails.
Signature
declare const layerInitialMessage: <S extends Schema.Constraint, R2>( schema: S, build: Effect.Effect<S["Type"], never, R2>) => Layer.Layer<InitialMessage, never, S["EncodingServices"] | R2>Since v4.0.0
makeInitialMessage
Section titled “makeInitialMessage”Runs an effect, encodes its result with the schema’s JSON codec, and returns the encoded value together with collected transferables.
Signature
declare const makeInitialMessage: <S extends Schema.Constraint, E, R2>( schema: S, effect: Effect.Effect<S["Type"], E, R2>) => Effect.Effect< readonly [data: unknown, transferables: ReadonlyArray<globalThis.Transferable>], E | Schema.SchemaError, S["EncodingServices"] | R2>Since v4.0.0
InitialMessage (namespace)
Section titled “InitialMessage (namespace)”Types related to the encoded initial message exchanged with an RPC worker.
Since v4.0.0
Encoded (interface)
Section titled “Encoded (interface)”Tagged wire representation of an RPC worker initial message after schema encoding.
Signature
export interface Encoded { readonly _tag: "InitialMessage" readonly value: unknown}Since v4.0.0