Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created December 2, 2017 15:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Delayed Promise
const reruns = 10;
const delayedPromise = (iterations) => {
return new Promise((resolve) => {
const delay = 1000;
setTimeout(() => {
if (iterations > 0) {
iterations -= 1;
console.log('Iteration', iterations);
delayedPromise(iterations).then(resolve);
} else {
resolve(`All jobs finished.`);
}
}, delay);
});
};
delayedPromise(reruns).then((status) => console.log(status));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment