Skip to content
1 min read · 133 words

Function: createWorkerTransport()

ts
function createWorkerTransport(
  spec: IsolatedServiceSpec,
  options: SpawnIsolatedOptions,
): IsolationTransport;

Defined in: src/batteries/isolation/browser.ts:182

Build an IsolationTransport that spawns/re-spawns a real browser Worker per SpawnIsolatedOptions.worker.

Parameters

ParameterType
specIsolatedServiceSpec
optionsSpawnIsolatedOptions

Returns

IsolationTransport

Remarks

connect() resolves the Worker (constructing it for a string | URL spec, or awaiting a WorkerResolver), wraps it in a PortLike (postpostMessage with any @nhtio/adk/batteries/isolation!transfer-marked values unwrapped into the transfer list; onMessageaddEventListener('message', ...)), and wires the worker's 'error'/'messageerror' events to the transport's onCrash handlers. terminate() calls worker.terminate(). createIsolatedService's recycle() re-enters this SAME connect() — since a resolver is invoked fresh on every call, it is the single source of Worker creation for the service's whole lifetime (every respawn goes through it, never a cached instance).