Last active
March 4, 2019 23:44
-
-
Save TravelingTechGuy/3f9530004daf67932bb2149fa22a6a97 to your computer and use it in GitHub Desktop.
A delay function that can be used with async-await
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
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
// Sample code using `delay` | |
const test = async () => { | |
const time = () => console.log((new Date).toLocaleTimeString()); | |
time(); | |
await delay(1000); | |
time(); | |
await delay(3000); | |
time(); | |
}; | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment