API reference / @evolu/web / index / createSharedWebWorker

Function: createSharedWebWorker()

function createSharedWebWorker<Input, Output>(
  name,
  createWebWorker,
): Worker<Input, Output>;

Defined in: SharedWebWorker.ts:59

Creates a shared Web Worker using BroadcastChannel and Web Locks. This allows multiple tabs to share a single Web Worker instance. The first tab to acquire the lock becomes the owner and runs the worker. Other tabs act as proxies, forwarding messages to the owner.

Type Parameters

Type Parameter
Input
Output

Parameters

ParameterType
namestring & Brand<"SimpleName">
createWebWorker() => Worker

Returns

Worker<Input, Output>

Was this page helpful?