Skip to content

Commit 674d9ad

Browse files
committed
Add artifical delay to timer fired funcs
1 parent cf7b398 commit 674d9ad

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

timer-fired/app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
function helloWorld() {
2+
sleepSync(100);
23
console.log('hello, world!');
34
}
45

56
setTimeout(helloWorld, 500);
67

78
setTimeout(() => {
9+
sleepSync(100);
810
console.log('anonymous, hello world!');
911
}, 1000);
1012

1113
setInterval(helloWorld, 1500);
14+
15+
function sleepSync(milliseconds) {
16+
const start = Date.now();
17+
while (Date.now() - start < milliseconds) {
18+
// Busy-wait, blocks the main thread
19+
}
20+
}

0 commit comments

Comments
 (0)