Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. async function waitFor(ms: number): Promise<void> {
  2. return new Promise(resolve => setTimeout(resolve, ms));
  3. }
  4.  
  5. /**
  6. * A promise loop that can be canceled by returning true in the callback async function.
  7. */
  8. async function promiseLoop(intervalMS: number, func: Function): Promise<void> {
  9. const endLoop = await func();
  10.  
  11. if (endLoop) return;
  12.  
  13. await waitFor(intervalMS);
  14.  
  15. await promiseLoop(intervalMS, func);
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement