Created
March 14, 2018 14:51
-
-
Save nloding/f53de881f62a7b8724bdc7738118bb24 to your computer and use it in GitHub Desktop.
async wrapper for setTimeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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