UNPKG

@xylabs/threads

Version:

Web workers & worker threads as simple as a function call

15 lines (11 loc) 462 B
/* eslint-disable @typescript-eslint/no-explicit-any */ type UnsubscribeFn = () => void export interface AbstractedWorkerAPI { isWorkerRuntime(): boolean postMessageToMaster(message: any, transferList?: Transferable[]): void subscribeToMasterMessages(onMessage: (data: any) => void): UnsubscribeFn } export type WorkerFunction = ((...args: any[]) => any) | (() => any) export type WorkerModule<Keys extends string> = { [key in Keys]: WorkerFunction }