-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.ts
More file actions
31 lines (20 loc) · 767 Bytes
/
Copy pathruntime.ts
File metadata and controls
31 lines (20 loc) · 767 Bytes
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
export let runtime: IRuntime;
export let realRuntime: any;
type TickCallback = (runtime: IRuntime) => void;
const tickCallbacks = new Set<TickCallback>();
export function exportRuntime(passedRuntime: IRuntime) {
if (runtime) throw new Error("Can't register runtime twice!");
runtime = passedRuntime;
runtime.addEventListener('tick', () => {
if (!tickCallbacks.size) return;
for (const callback of tickCallbacks) callback(runtime);
tickCallbacks.clear();
});
}
export function exportRealRuntime(passedRealRuntime: any) {
if (realRuntime) throw new Error("Can't register runtime twice!");
realRuntime = passedRealRuntime;
}
export function nextTick(callback: TickCallback) {
tickCallbacks.add(callback);
}