Skip to main content Link Search Menu Expand Document (external link)

WorkerRunner overview

Added in v1.0.0


Table of contents


constructors

make

Signature

export declare const make: <I, E, R, O>(
  process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
  options?: Runner.Options<I, O, E>
) => Effect.Effect<void, WorkerError, PlatformRunner | R | Scope.Scope>

Added in v1.0.0

makeSerialized

Signature

export declare const makeSerialized: <
  R,
  I,
  A extends Schema.TaggedRequest.All,
  const Handlers extends SerializedRunner.Handlers<A>
>(
  schema: Schema.Schema<A, I, R>,
  handlers: Handlers
) => Effect.Effect<void, WorkerError, PlatformRunner | Scope.Scope | R | SerializedRunner.HandlersContext<Handlers>>

Added in v1.0.0

run

Signature

export declare const run: <I, E, R, O>(
  process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
  options?: Runner.Options<I, O, E>
) => Effect.Effect<never, WorkerError, PlatformRunner | R>

Added in v1.0.0

layers

layer

Signature

export declare const layer: <I, E, R, O>(
  process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
  options?: Runner.Options<I, O, E> | undefined
) => Layer.Layer<never, WorkerError, R | PlatformRunner>

Added in v1.0.0

layerSerialized

Signature

export declare const layerSerialized: <
  R,
  I,
  A extends Schema.TaggedRequest.All,
  const Handlers extends SerializedRunner.Handlers<A>
>(
  schema: Schema.Schema<A, I, R>,
  handlers: Handlers
) => Layer.Layer<never, WorkerError, PlatformRunner | R | SerializedRunner.HandlersContext<Handlers>>

Added in v1.0.0

models

BackingRunner (interface)

Signature

export interface BackingRunner<I, O> {
  readonly run: <A, E, R>(
    handler: (portId: number, message: I) => Effect.Effect<A, E, R>
  ) => Effect.Effect<never, E | WorkerError, R>
  readonly send: (portId: number, message: O, transfers?: ReadonlyArray<unknown>) => Effect.Effect<void>
}

Added in v1.0.0

BackingRunner (namespace)

Added in v1.0.0

Message (type alias)

Signature

export type Message<I> = readonly [request: 0, I] | readonly [close: 1]

Added in v1.0.0

PlatformRunner (interface)

Signature

export interface PlatformRunner {
  readonly [PlatformRunnerTypeId]: PlatformRunnerTypeId
  readonly start: <I, O>() => Effect.Effect<BackingRunner<I, O>, WorkerError>
}

Added in v1.0.0

Runner (namespace)

Added in v1.0.0

Options (interface)

Signature

export interface Options<I, O, E> {
  readonly decode?: (message: unknown) => Effect.Effect<I, WorkerError>
  readonly encodeOutput?: (request: I, message: O) => Effect.Effect<unknown, WorkerError>
  readonly encodeError?: (request: I, error: E) => Effect.Effect<unknown, WorkerError>
}

Added in v1.0.0

SerializedRunner (namespace)

Added in v1.0.0

Handlers (type alias)

Signature

export type Handlers<A extends Schema.TaggedRequest.All> = {
  readonly [K in A["_tag"]]: Extract<A, { readonly _tag: K }> extends Schema.SerializableWithResult<
    infer S,
    infer _SI,
    infer _SR,
    infer A,
    infer _AI,
    infer E,
    infer _EI,
    infer _RR
  >
    ? (
        _: S
      ) => Stream.Stream<A, E, any> | Effect.Effect<A, E, any> | Layer.Layer<any, E, any> | Layer.Layer<never, E, any>
    : never
}

Added in v1.0.0

HandlersContext (type alias)

Signature

export type HandlersContext<Handlers extends Record<string, (...args: ReadonlyArray<any>) => any>> =
  | Exclude<
      {
        [K in keyof Handlers]: ReturnType<Handlers[K]> extends Stream.Stream<infer _A, infer _E, infer R> ? R : never
      }[keyof Handlers],
      InitialContext<Handlers>
    >
  | InitialEnv<Handlers>

Added in v1.0.0

tags

PlatformRunner

Signature

export declare const PlatformRunner: Context.Tag<PlatformRunner, PlatformRunner>

Added in v1.0.0

type ids

PlatformRunnerTypeId

Signature

export declare const PlatformRunnerTypeId: typeof PlatformRunnerTypeId

Added in v1.0.0

PlatformRunnerTypeId (type alias)

Signature

export type PlatformRunnerTypeId = typeof PlatformRunnerTypeId

Added in v1.0.0