Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
Created August 19, 2022 14:48
Show Gist options
  • Save mjumbewu/97687f637647af343eeaf4b97c390bb8 to your computer and use it in GitHub Desktop.
Save mjumbewu/97687f637647af343eeaf4b97c390bb8 to your computer and use it in GitHub Desktop.
A simple JavaScript function to allow using setTimeout with async/await.
function timeout(duration) {
return new Promise((resolve) => {
setTimeout(resolve, duration);
});
}
/*
Example:
async function dostuff() {
await timeout(1000);
// ...
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment