-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.js
More file actions
63 lines (57 loc) · 1.57 KB
/
Copy pathruntime.js
File metadata and controls
63 lines (57 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { startEvents } from "./runtime/events.js";
import { startSignals } from "./runtime/signals.js";
import { createRuntimeController, normalizeRuntimeStartArgs } from "./runtime/shared.js";
export function start(rootOrOptions, planArg, optionsArg) {
const { root, plan, options } = normalizeRuntimeStartArgs(rootOrOptions, planArg, optionsArg);
assertRuntimePlan(plan);
const children = [];
let stopped = false;
try {
let signals;
if (plan.signals) {
signals = startSignals(root, plan.signals, {
elements: plan.elements,
signal: options.signal,
onDiagnostic: options.onDiagnostic
});
children.push(signals);
}
if (plan.events) {
children.push(startEvents(root, plan.events, {
elements: plan.elements,
signal: options.signal,
signals,
importModule: options.importModule,
onDiagnostic: options.onDiagnostic
}));
}
} catch (error) {
stopChildren(children);
throw error;
}
return createRuntimeController({
get stopped() {
return stopped;
},
stop() {
if (stopped) {
return;
}
stopped = true;
stopChildren(children);
}
}, options.signal);
}
function stopChildren(children) {
for (const child of [...children].reverse()) {
child.stop();
}
}
function assertRuntimePlan(plan) {
if (!plan || typeof plan !== "object") {
throw new TypeError("Runtime plan must be an object.");
}
if (plan.version !== 1) {
throw new Error(`Unsupported runtime plan version: ${String(plan.version)}.`);
}
}