Skip to content

Instantly share code, notes, and snippets.

@sharjeel619
Last active March 21, 2024 21:39
Show Gist options
  • Save sharjeel619/332f190aadbc8309312a54e7739960c2 to your computer and use it in GitHub Desktop.
Save sharjeel619/332f190aadbc8309312a54e7739960c2 to your computer and use it in GitHub Desktop.
Alternative to setTimeout
// 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