exposeWorkerApi<TApi>
Exposes handlers to the main thread. Call it once, at the top level of a worker entry point.
A handler that throws or rejects answers with a SerializedWorkerError, which the caller receives as a WorkerCallError. An unknown method answers with an error too, so a caller never waits for nothing.
Import:
import { exposeWorkerApi } from '@mnaoumov/obsidian-lib/worker-protocol';Signature:
function exposeWorkerApi(handlers: WorkerApiHandlers<TApi>, port: WorkerMessagePort | undefined): voidParameters:
| Parameter | Type | Description |
|---|---|---|
handlers |
WorkerApiHandlers<TApi> | The handlers. |
port |
WorkerMessagePort | undefined | The port to talk through. Defaults to the worker’s global scope. |
Returns: void