Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. function sleep(duration) {
  2. return new Promise((resolve, reject) => {
  3. setTimeout(() => {
  4. resolve();
  5. }, duration);
  6. });
  7. }
  8.  
  9. // usage
  10. async function fn() {
  11. doStuff();
  12. // sleep for 1 second
  13. await sleep(1000);
  14. doAnotherStuff();
  15. }
  16.  
  17. function doStuff() {
  18. console.log('foo');
  19. }
  20.  
  21. function doAnotherStuff() {
  22. console.log('bar');
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement