Created
December 2, 2017 15:17
-
-
Save bennycode/71c4b859c5b277d4660ddc5265a589a1 to your computer and use it in GitHub Desktop.
Delayed Promise
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
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