Even thought setTimeout
isn't always the best solution we always end up using it for some reason. Since I quite like the async/await
syntax I create a small snippets to await
a setTimeout
.
// === Snippet ===
const wait = (timeToDelay) => new Promise((resolve) => setTimeout(resolve, timeToDelay));
// === Usage ===
// Some code before
await wait(1000); // wait 1s
// Code runs after 1s
Top comments (2)
Nice snippet! Thanks for sharing!
glad i'm found this, this 2 line code really helps my problem
thanks brad