Skip to content

Instantly share code, notes, and snippets.

@nloding
Created March 14, 2018 14:51
Show Gist options
  • Select an option

  • Save nloding/f53de881f62a7b8724bdc7738118bb24 to your computer and use it in GitHub Desktop.

Select an option

Save nloding/f53de881f62a7b8724bdc7738118bb24 to your computer and use it in GitHub Desktop.
async wrapper for setTimeout
// credit: https://codingwithspike.wordpress.com/2018/03/10/making-settimeout-an-async-await-function/
async function wait(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
// usage:
async function doRequests(uris) {
for(const uri of uris) {
await fetch(uri);
await wait(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment