Setu-TS
    Preparing search index...

    Interface IWorkerHandle

    Handle to one spawned worker thread, normalized across web Worker (Deno/Bun) and node:worker_threads (Node).

    Messages travel by structured clone. Listeners receive the message payload directly (already unwrapped from MessageEvent on web-worker runtimes).

    0.1.0

    interface IWorkerHandle {
        onError(listener: (error: Error) => void): void;
        onExit?(listener: (code: number | null) => void): void;
        onMessage(listener: (message: unknown) => void): void;
        postMessage(message: unknown): void;
        terminate(): Promise<void>;
    }
    Index
    • Registers a listener for worker-level errors (module evaluation failure, uncaught error in the worker).

      Parameters

      • listener: (error: Error) => void

        Receives the normalized error

      Returns void

    • Registers a listener for the worker's THREAD ENDING, however it ended — a clean self-termination included. This is distinct from onError, which reports a failure the worker survived long enough to report; a worker that simply stops raises no error at all.

      Optional, and its absence is load-bearing information rather than a shortfall to work around: a host omits it when its runtime emits nothing when a worker ends, so a consumer MUST treat absence as "this runtime cannot tell me a worker died" and not as "no worker has died". Ask IWorkerHost.reportsExit before spawning if the answer changes what you configure.

      Fires for a host-requested terminate() too on runtimes that implement it that way, so a consumer that terminates deliberately must track that itself rather than reading every exit as a crash.

      Parameters

      • listener: (code: number | null) => void

        Receives the exit code when the runtime reports one, and null when it ends the worker without one

      Returns void

      0.3.0

    • Registers a listener for messages from the worker.

      Parameters

      • listener: (message: unknown) => void

        Receives each message payload

      Returns void

    • Posts a structured-clonable message to the worker.

      Parameters

      • message: unknown

        The message payload

      Returns void