/** * Client-side worker primitives shared by browser, Node, and Bun adapters. * * This module defines the platform-neutral `Worker` client, the `WorkerPlatform` * service that creates workers by numeric id, and the `Spawner` service used to * find platform-specific worker instances. `makePlatform` wraps platform setup * and listen hooks into a `WorkerPlatform`, buffers outgoing messages until the * worker is ready, runs incoming messages with Effect handlers, and ties worker * cleanup to scope lifetime. * * @stability unstable * @since 4.0.0 */ import * as Context from "../Context.ts"; import type * as Deferred from "../Deferred.ts"; import * as Effect from "../Effect.ts"; import * as Layer from "../Layer.ts"; import * as Scope from "../Scope.ts"; import { WorkerError } from "./WorkerError.ts"; declare const WorkerPlatform_base: Context.ServiceClass(id: number) => Effect.Effect, WorkerError, Spawner>; }>; /** * Service that spawns effect `Worker` instances for numeric worker ids using * the configured `Spawner`. * * @stability unstable * @category services * @since 4.0.0 */ export declare class WorkerPlatform extends WorkerPlatform_base { } /** * Effect-based worker abstraction that can send input messages and run a * long-lived handler for output messages, failing with `WorkerError` or handler * errors. * * @stability unstable * @category models * @since 4.0.0 */ export interface Worker { readonly send: (message: I, transfers?: ReadonlyArray) => Effect.Effect; readonly run: (handler: (message: O) => Effect.Effect, options?: { readonly onSpawn?: Effect.Effect | undefined; } | undefined) => Effect.Effect; } /** * Wraps platform-specific send and run functions into a `Worker`, translating * platform ready/data messages and running the optional `onSpawn` effect when * the worker reports readiness. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const makeUnsafe: (options: { readonly send: (message: unknown, transfers?: ReadonlyArray) => Effect.Effect; readonly run: (handler: (message: PlatformMessage) => Effect.Effect) => Effect.Effect; }) => Worker; /** * Internal worker platform protocol message: `[0]` signals readiness and * `[1, payload]` carries data. * * @stability unstable * @category models * @since 4.0.0 */ export type PlatformMessage = readonly [ready: 0] | readonly [data: 1, unknown]; /** * Phantom identifier for the service that maps worker ids to platform-specific * worker instances. * * @stability unstable * @category models * @since 4.0.0 */ export interface Spawner { readonly _: unique symbol; } /** * Service tag for the worker `SpawnerFn`. * * @stability unstable * @category services * @since 4.0.0 */ export declare const Spawner: Context.Service>; /** * Function that creates or locates a platform-specific worker instance for a * numeric worker id. * * @stability unstable * @category models * @since 4.0.0 */ export interface SpawnerFn { (id: number): W; } /** * Creates a layer that provides a worker `Spawner` service from a `SpawnerFn`. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerSpawner: (spawner: SpawnerFn) => Layer.Layer; /** * Creates a `WorkerPlatform` from platform-specific setup and listen hooks, * buffering sent messages until the worker is ready and scoping port cleanup to * the worker run. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const makePlatform: () =>

void; }>(options: { readonly setup: (options: { readonly worker: W; readonly scope: Scope.Scope; }) => Effect.Effect; readonly listen: (options: { readonly port: P; readonly emit: (data: any) => void; readonly deferred: Deferred.Deferred; readonly scope: Scope.Scope; }) => Effect.Effect; }) => WorkerPlatform["Service"]; export {}; //# sourceMappingURL=Worker.d.ts.map