Skip to content

RpcWorker

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.

5 exports Added in v4.0.0 Source

Decoding

Reads the protocol initial message and decodes it with the supplied schema, failing if no initial message is available or decoding fails.

Signature

declare function initialMessage<S extends Constraint>(
  schema: S,
): Effect<S["Type"], NoSuchElementError | SchemaError, Protocol | S["DecodingServices"]>;

Encoding

Runs an effect, encodes its result with the schema's JSON codec, and returns the encoded value together with collected transferables.

Signature

declare function makeInitialMessage<S extends Constraint, E, R2>(schema: S, effect: Effect<S["Type"], E, R2>): Effect<readonly [unknown, readonly Array<Transferable>], SchemaError | E, R2 | S["EncodingServices"]>

Layers

Provides the InitialMessage service from a schema and build effect, capturing the layer context and dying if schema encoding fails.

Signature

declare function layerInitialMessage<S extends Constraint, R2>(
  schema: S,
  build: Effect<S["Type"], never, R2>,
): Layer<InitialMessage, never, R2 | S["EncodingServices"]>;

Other

Types related to the encoded initial message exchanged with an RPC worker.

Services

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 InitialMessage extends Shape<"effect/rpc/RpcWorker/InitialMessage", Effect<readonly [unknown, readonly Array<Transferable>], never, never>, this> {
  constructor(_: never);
}