UNPKG

1.36 kBTypeScriptView Raw
1import { FunctionThread, ModuleThread, StripAsync, Worker as WorkerType } from "../types/master";
2import { WorkerFunction, WorkerModule } from "../types/worker";
3declare type ArbitraryWorkerInterface = WorkerFunction & WorkerModule<string> & {
4 somekeythatisneverusedinproductioncode123: "magicmarker123";
5};
6declare type ArbitraryThreadType = FunctionThread<any, any> & ModuleThread<any>;
7declare type ExposedToThreadType<Exposed extends WorkerFunction | WorkerModule<any>> = Exposed extends ArbitraryWorkerInterface ? ArbitraryThreadType : Exposed extends WorkerFunction ? FunctionThread<Parameters<Exposed>, StripAsync<ReturnType<Exposed>>> : Exposed extends WorkerModule<any> ? ModuleThread<Exposed> : never;
8/**
9 * Spawn a new thread. Takes a fresh worker instance, wraps it in a thin
10 * abstraction layer to provide the transparent API and verifies that
11 * the worker has initialized successfully.
12 *
13 * @param worker Instance of `Worker`. Either a web worker, `worker_threads` worker or `tiny-worker` worker.
14 * @param [options]
15 * @param [options.timeout] Init message timeout. Default: 10000 or set by environment variable.
16 */
17export declare function spawn<Exposed extends WorkerFunction | WorkerModule<any> = ArbitraryWorkerInterface>(worker: WorkerType, options?: {
18 timeout?: number;
19}): Promise<ExposedToThreadType<Exposed>>;
20export {};