BrowserWorker.ts
BrowserWorker.ts overview
Section titled “BrowserWorker.ts overview”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.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”layers
Section titled “layers”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
layerPlatformfor providing only the browser worker platform
Signature
declare const layer: ( spawn: (id: number) => Worker | SharedWorker | MessagePort) => Layer.Layer<Worker.WorkerPlatform | Worker.Spawner>Since v4.0.0
layerPlatform
Section titled “layerPlatform”Layer that provides the browser WorkerPlatform for Worker, SharedWorker, and MessagePort communication.
Signature
declare const layerPlatform: Layer.Layer<Worker.WorkerPlatform, never, never>Since v4.0.0