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.
Layers
Signature
declare function layer(
spawn: (id: number) => Worker | SharedWorker | MessagePort,
): Layer<WorkerPlatform | Spawner>;layerPlatform
Added in v4.0.0
Source
Layer that provides the browser WorkerPlatform for Worker, SharedWorker, and MessagePort communication.
Signature
declare const layerPlatform: Layer.Layer<Worker.WorkerPlatform>;
Creates browser worker layers by combining the default
WorkerPlatformwith a spawner forWorker,SharedWorker, orMessagePortinstances.When to use
Use when you need both the browser
WorkerPlatformand aSpawnerfrom one layer.Details
The
spawncallback receives the numeric worker id and may return aWorker,SharedWorker, orMessagePort.Gotchas
Scope finalization sends the worker close protocol over the port. Dedicated workers created by
spawnare not terminated by this layer.See
layerPlatformfor providing only the browser worker platform