nPhoenix

Async Await

Aug 13th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function timeout(ms) {
  2.     return new Promise(resolve => setTimeout(resolve, ms));
  3. };
  4.  
  5. async function sleep (forHowLong) {
  6.     await timeout(forHowLong);
  7. };
  8.  
  9. async function asyncFn () {
  10.     await sleep(0);
  11.     console.log(3);
  12.     await sleep(1000);
  13.     console.log(2);
  14.     await sleep(1000);
  15.     console.log(1);
  16.     await sleep(1000);
  17.     console.log('DONE');
  18. };
  19.  
  20. asyncFn();
Advertisement
Add Comment
Please, Sign In to add comment