Last active
May 22, 2018 17:51
-
-
Save sillero/48e7369a4f964dac63c25a5f27639e09 to your computer and use it in GitHub Desktop.
JS helpers for delayed execution with async/await
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function delay(ms: number) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
export async function delayedRepeat(ms: number, repetitions: number, callback: (index) => any) { | |
for (let i = 1; i <= repetitions; i++) { | |
await delay(ms); | |
callback(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment