@xylabs/threads
Version:
Web workers & worker threads as simple as a function call
1 lines • 2.11 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/symbols.ts","../../../src/master/thread.ts"],"sourcesContent":["export const $errors = Symbol('thread.errors')\nexport const $events = Symbol('thread.events')\nexport const $terminate = Symbol('thread.terminate')\nexport const $transferable = Symbol('thread.transferable')\nexport const $worker = Symbol('thread.worker')\n","/* eslint-disable import-x/no-internal-modules */\nimport type { Observable } from 'observable-fns'\n\nimport {\n $errors, $events, $terminate,\n} from '../symbols.ts'\nimport type { Thread as ThreadType, WorkerEvent } from '../types/master.ts'\n\nfunction fail(message: string): never {\n throw new Error(message)\n}\n\nexport type Thread = ThreadType\n\n/** Thread utility functions. Use them to manage or inspect a `spawn()`-ed thread. */\nexport const Thread = {\n /** Return an observable that can be used to subscribe to all errors happening in the thread. */\n errors<ThreadT extends ThreadType>(thread: ThreadT): Observable<Error> {\n return thread[$errors] || fail('Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.')\n },\n /** Return an observable that can be used to subscribe to internal events happening in the thread. Useful for debugging. */\n events<ThreadT extends ThreadType>(thread: ThreadT): Observable<WorkerEvent> {\n return thread[$events] || fail('Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.')\n },\n /** Terminate a thread. Remember to terminate every thread when you are done using it. */\n terminate<ThreadT extends ThreadType>(thread: ThreadT) {\n return thread[$terminate]()\n },\n}\n"],"mappings":";AAAO,IAAM,UAAU,uBAAO,eAAe;AACtC,IAAM,UAAU,uBAAO,eAAe;AACtC,IAAM,aAAa,uBAAO,kBAAkB;;;ACMnD,SAAS,KAAK,SAAwB;AACpC,QAAM,IAAI,MAAM,OAAO;AACzB;AAKO,IAAM,SAAS;AAAA;AAAA,EAEpB,OAAmC,QAAoC;AACrE,WAAO,OAAO,OAAO,KAAK,KAAK,qGAAqG;AAAA,EACtI;AAAA;AAAA,EAEA,OAAmC,QAA0C;AAC3E,WAAO,OAAO,OAAO,KAAK,KAAK,sGAAsG;AAAA,EACvI;AAAA;AAAA,EAEA,UAAsC,QAAiB;AACrD,WAAO,OAAO,UAAU,EAAE;AAAA,EAC5B;AACF;","names":[]}