/** * @since 1.0.0 */ import type * as Context from "effect/Context"; import type * as Deferred from "effect/Deferred"; import type * as Duration from "effect/Duration"; import type * as Effect from "effect/Effect"; import type { LazyArg } from "effect/Function"; import type * as Layer from "effect/Layer"; import type * as ParseResult from "effect/ParseResult"; import type * as Pool from "effect/Pool"; import type * as Schema from "effect/Schema"; import type * as Scope from "effect/Scope"; import type * as Stream from "effect/Stream"; import type { WorkerError, WorkerErrorFrom } from "./WorkerError.js"; /** * @since 1.0.0 * @category models */ export interface BackingWorker { readonly send: (message: I, transfers?: ReadonlyArray) => Effect.Effect; readonly run: (handler: (_: BackingWorker.Message) => Effect.Effect) => Effect.Effect; } /** * @since 1.0.0 * @category models */ export declare namespace BackingWorker { /** * @since 1.0.0 * @category models */ type Message = readonly [ready: 0] | readonly [data: 1, O]; } /** * @since 1.0.0 * @category type ids */ export declare const PlatformWorkerTypeId: unique symbol; /** * @since 1.0.0 * @category type ids */ export type PlatformWorkerTypeId = typeof PlatformWorkerTypeId; /** * @since 1.0.0 * @category models */ export interface PlatformWorker { readonly [PlatformWorkerTypeId]: PlatformWorkerTypeId; readonly spawn: (id: number) => Effect.Effect, WorkerError, Spawner>; } /** * @since 1.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; }) => PlatformWorker; /** * @since 1.0.0 * @category tags */ export declare const PlatformWorker: Context.Tag; /** * @since 1.0.0 * @category models */ export interface Worker { readonly id: number; readonly execute: (message: I) => Stream.Stream; readonly executeEffect: (message: I) => Effect.Effect; } /** * @since 1.0.0 * @category models */ export interface Spawner { readonly _: unique symbol; } /** * @since 1.0.0 * @category tags */ export declare const Spawner: Context.Tag>; /** * @since 1.0.0 * @category models */ export interface SpawnerFn { (id: number): W; } /** * @since 1.0.0 * @category models */ export declare namespace Worker { /** * @since 1.0.0 * @category models */ interface Options { readonly encode?: ((message: I) => Effect.Effect) | undefined; readonly initialMessage?: LazyArg | undefined; } /** * @since 1.0.0 * @category models */ type Request = readonly [id: number, data: 0, I, trace: Span | undefined] | readonly [id: number, interrupt: 1]; /** * @since 1.0.0 * @category models */ type Span = readonly [traceId: string, spanId: string, sampled: boolean]; /** * @since 1.0.0 * @category models */ type Response = readonly [id: number, data: 0, ReadonlyArray] | readonly [id: number, end: 1] | readonly [id: number, end: 1, ReadonlyArray] | readonly [id: number, error: 2, E] | readonly [id: number, defect: 3, Schema.CauseEncoded]; } /** * @since 1.0.0 * @category models */ export interface WorkerPool { readonly backing: Pool.Pool, WorkerError>; readonly broadcast: (message: I) => Effect.Effect; readonly execute: (message: I) => Stream.Stream; readonly executeEffect: (message: I) => Effect.Effect; } /** * @since 1.0.0 * @category models */ export declare namespace WorkerPool { /** * @since 1.0.0 * @category models */ type Options = Worker.Options & ({ readonly onCreate?: (worker: Worker) => Effect.Effect; readonly size: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; } | { readonly onCreate?: (worker: Worker) => Effect.Effect; readonly minSize: number; readonly maxSize: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; readonly timeToLive: Duration.DurationInput; }); } /** * @since 1.0.0 * @category type ids */ export declare const WorkerManagerTypeId: unique symbol; /** * @since 1.0.0 * @category type ids */ export type WorkerManagerTypeId = typeof WorkerManagerTypeId; /** * @since 1.0.0 * @category models */ export interface WorkerManager { readonly [WorkerManagerTypeId]: WorkerManagerTypeId; readonly spawn: (options: Worker.Options) => Effect.Effect, WorkerError, Scope.Scope | Spawner>; } /** * @since 1.0.0 * @category tags */ export declare const WorkerManager: Context.Tag; /** * @since 1.0.0 * @category constructors */ export declare const makeManager: Effect.Effect; /** * @since 1.0.0 * @category layers */ export declare const layerManager: Layer.Layer; /** * @since 1.0.0 * @category constructors */ export declare const makePool: (options: WorkerPool.Options) => Effect.Effect, WorkerError, WorkerManager | Spawner | Scope.Scope>; /** * @since 1.0.0 * @category constructors */ export declare const makePoolLayer: (tag: Context.Tag>, options: WorkerPool.Options) => Layer.Layer; /** * @since 1.0.0 * @category models */ export interface SerializedWorker { readonly id: number; readonly execute: (message: Req) => Req extends Schema.WithResult ? Stream.Stream : never; readonly executeEffect: (message: Req) => Req extends Schema.WithResult ? Effect.Effect : never; } /** * @since 1.0.0 * @category models */ export declare namespace SerializedWorker { /** * @since 1.0.0 * @category models */ type Options = Extract extends never ? { readonly initialMessage?: LazyArg; } : { readonly initialMessage: LazyArg>; }; } /** * @since 1.0.0 * @category models */ export interface SerializedWorkerPool { readonly backing: Pool.Pool, WorkerError>; readonly broadcast: (message: Req) => Req extends Schema.WithResult ? Effect.Effect : never; readonly execute: (message: Req) => Req extends Schema.WithResult ? Stream.Stream : never; readonly executeEffect: (message: Req) => Req extends Schema.WithResult ? Effect.Effect : never; } /** * @since 1.0.0 * @category models */ export declare namespace SerializedWorkerPool { /** * @since 1.0.0 * @category models */ type Options = SerializedWorker.Options & ({ readonly onCreate?: (worker: Worker) => Effect.Effect; readonly size: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; } | { readonly onCreate?: (worker: Worker) => Effect.Effect; readonly minSize: number; readonly maxSize: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; readonly timeToLive: Duration.DurationInput; }); } /** * @since 1.0.0 * @category constructors */ export declare const makeSerialized: (options: SerializedWorker.Options) => Effect.Effect, WorkerError, WorkerManager | Spawner | Scope.Scope>; /** * @since 1.0.0 * @category constructors */ export declare const makePoolSerialized: (options: SerializedWorkerPool.Options) => Effect.Effect, WorkerError, WorkerManager | Spawner | Scope.Scope>; /** * @since 1.0.0 * @category layers */ export declare const makePoolSerializedLayer: (tag: Context.Tag>, options: SerializedWorkerPool.Options) => Layer.Layer; /** * @since 1.0.0 * @category layers */ export declare const layerSpawner: (spawner: SpawnerFn) => Layer.Layer; //# sourceMappingURL=Worker.d.ts.map