Skip to content

BrowserWorker

Parent-side browser platform for Effect workers.

layerPlatform provides the WorkerPlatform used to communicate with a browser Worker, SharedWorker, or MessagePort through Effect's worker protocol. layer combines that platform with a Spawner built from a callback that creates or returns the worker endpoint for each worker id.

2 exports Added in v4.0.0 Source

Layers

layer

Added in v4.0.0 Source

Creates browser worker layers by combining the default WorkerPlatform with a spawner for Worker, SharedWorker, or MessagePort instances.

When to use

Use when you need both the browser WorkerPlatform and a Spawner from one layer.

Details

The spawn callback receives the numeric worker id and may return a Worker, SharedWorker, or MessagePort.

Gotchas

Scope finalization sends the worker close protocol over the port. Dedicated workers created by spawn are not terminated by this layer.

See

Signature

declare function layer(
  spawn: (id: number) => Worker | SharedWorker | MessagePort,
): Layer<WorkerPlatform | Spawner>;

Layer that provides the browser WorkerPlatform for Worker, SharedWorker, and MessagePort communication.

Signature

declare const layerPlatform: Layer.Layer<Worker.WorkerPlatform>;