UNPKG

1.07 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Thread = void 0;
4const symbols_1 = require("../symbols");
5function fail(message) {
6 throw Error(message);
7}
8/** Thread utility functions. Use them to manage or inspect a `spawn()`-ed thread. */
9exports.Thread = {
10 /** Return an observable that can be used to subscribe to all errors happening in the thread. */
11 errors(thread) {
12 return thread[symbols_1.$errors] || fail("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.");
13 },
14 /** Return an observable that can be used to subscribe to internal events happening in the thread. Useful for debugging. */
15 events(thread) {
16 return thread[symbols_1.$events] || fail("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.");
17 },
18 /** Terminate a thread. Remember to terminate every thread when you are done using it. */
19 terminate(thread) {
20 return thread[symbols_1.$terminate]();
21 }
22};