Skip to content

Instantly share code, notes, and snippets.

@mischah
Created April 14, 2019 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mischah/dd05a2b2be4aabee0b05da37fb94d403 to your computer and use it in GitHub Desktop.
Save mischah/dd05a2b2be4aabee0b05da37fb94d403 to your computer and use it in GitHub Desktop.
Promisified setTimeout
// Promisified setTimeout
const delay = (duration = 0) =>
new Promise(resolve =>
setTimeout(() => {
resolve();
}, duration)
);
// Usage
async function myFunction() {
console.log('Do something');
await delay();
console.log('Do something else');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment