Skip to content

Instantly share code, notes, and snippets.

@TravelingTechGuy
Last active March 4, 2019 23:44
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 TravelingTechGuy/3f9530004daf67932bb2149fa22a6a97 to your computer and use it in GitHub Desktop.
Save TravelingTechGuy/3f9530004daf67932bb2149fa22a6a97 to your computer and use it in GitHub Desktop.
A delay function that can be used with async-await
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