Last active
March 21, 2024 21:39
-
-
Save sharjeel619/332f190aadbc8309312a54e7739960c2 to your computer and use it in GitHub Desktop.
Alternative to setTimeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These examples Block UI | |
let startTime = performance.now(); | |
while (performance.now() - startTime < 500) { | |
// // Do nothing for 500 ms to emulate extremely slow code | |
} | |
const wait = (ms) => { | |
const start = Date.now(); | |
let now = start; | |
while (now - start < ms) now = Date.now(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment