@xylabs/threads
Version:
Web workers & worker threads as simple as a function call
33 lines (31 loc) • 1.24 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/symbols.ts
var $errors = Symbol("thread.errors");
var $events = Symbol("thread.events");
var $terminate = Symbol("thread.terminate");
var $transferable = Symbol("thread.transferable");
var $worker = Symbol("thread.worker");
// src/master/thread.ts
function fail(message) {
throw new Error(message);
}
__name(fail, "fail");
var Thread = {
/** Return an observable that can be used to subscribe to all errors happening in the thread. */
errors(thread) {
return thread[$errors] || fail("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.");
},
/** Return an observable that can be used to subscribe to internal events happening in the thread. Useful for debugging. */
events(thread) {
return thread[$events] || fail("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.");
},
/** Terminate a thread. Remember to terminate every thread when you are done using it. */
terminate(thread) {
return thread[$terminate]();
}
};
export {
Thread
};
//# sourceMappingURL=thread.mjs.map