Skip to content

Instantly share code, notes, and snippets.

@sillero
Last active May 22, 2018 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sillero/48e7369a4f964dac63c25a5f27639e09 to your computer and use it in GitHub Desktop.
Save sillero/48e7369a4f964dac63c25a5f27639e09 to your computer and use it in GitHub Desktop.
JS helpers for delayed execution with async/await
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