API reference / @evolu/common / Worker / createInitializedWorkerWithHandlers

Function: createInitializedWorkerWithHandlers()

function createInitializedWorkerWithHandlers<Input, Output, Deps>(
  __namedParameters,
): Worker<Input, Output>;

Defined in: packages/common/src/Worker.ts:153

Creates a Worker with type-safe message handlers for each message type. This provides better type safety and organization compared to a single onMessage handler.

Type Parameters

Type Parameter
Input extends object
Output extends object & ["Output.onError must have an error property"]
Deps

Parameters

ParameterType
__namedParameters{ handlers: Omit<MessageHandlers<Input, Deps>, "init">; init: (initMessage, postMessage, withErrorReporting) => Promise<Deps | null>; }
__namedParameters.handlersOmit<MessageHandlers<Input, Deps>, "init">
__namedParameters.init(initMessage, postMessage, withErrorReporting) => Promise<Deps | null>

Returns

Worker<Input, Output>

Was this page helpful?