Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function waitFor(ms: number): Promise<void> {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- /**
- * A promise loop that can be canceled by returning true in the callback async function.
- */
- async function promiseLoop(intervalMS: number, func: Function): Promise<void> {
- const endLoop = await func();
- if (endLoop) return;
- await waitFor(intervalMS);
- await promiseLoop(intervalMS, func);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement