@xylabs/threads
Version:
Web workers & worker threads as simple as a function call
27 lines (26 loc) • 1.05 kB
JavaScript
// src/symbols.ts
var $errors = /* @__PURE__ */ Symbol("thread.errors");
var $events = /* @__PURE__ */ Symbol("thread.events");
var $terminate = /* @__PURE__ */ Symbol("thread.terminate");
// src/master/thread.ts
function fail(message) {
throw new Error(message);
}
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