Created
November 22, 2019 17:44
-
-
Save Artem-Schander/4b1f71b1eb9b5d54e26cb24d4cb75bc4 to your computer and use it in GitHub Desktop.
Recursive JavaScript function with delay in each loop
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 run = (cb, repeats, timeout = 100, i = 0) => { | |
cb(i) | |
setTimeout(() => { | |
++ i | |
if (repeats >= i + 1) run(cb, repeats, timeout, i) | |
}, timeout) | |
} | |
run(i => { | |
console.log(i) | |
}, 42, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment