-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.js
28 lines (28 loc) · 828 Bytes
/
program.js
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Program = void 0;
const disposable_1 = require("./disposable");
class Program extends disposable_1.Disposable {
constructor() {
super();
this.interval = undefined;
this.callbacks = [];
}
repeat(callback) {
this.callbacks.push(callback);
if (!this.interval) {
this.interval = setInterval(() => {
this.callbacks.forEach(async (callback) => {
// await will ensure all callbacks fire even if one throws.
await callback();
}, 20);
});
}
}
dispose() {
clearInterval(this.interval);
this.callbacks.length = 0;
super.dispose();
}
}
exports.Program = Program;