-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimers.ts
More file actions
28 lines (23 loc) · 721 Bytes
/
timers.ts
File metadata and controls
28 lines (23 loc) · 721 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
// Timers - demonstrates setTimeout and setInterval with the libuv event loop
let counter: number = 0;
function onTimeout(): void {
console.log(" [timeout] fired after 500ms");
}
function onInterval(): void {
counter = counter + 1;
if (counter == 1) {
console.log(" [interval] tick 1");
} else if (counter == 2) {
console.log(" [interval] tick 2");
} else if (counter == 3) {
console.log(" [interval] tick 3 - done!");
process.exit(0);
}
}
console.log("Timers Demo");
console.log(" scheduling setTimeout(500ms) and setInterval(200ms)");
console.log(" interval will fire 3 times then exit");
console.log("");
setTimeout(onTimeout, 500);
setInterval(onInterval, 200);
runEventLoop();