Last active
December 31, 2015 09:49
-
-
Save cuipengfei/7969763 to your computer and use it in GitHub Desktop.
functional js blocking event loop
This file contains hidden or 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
| function repeat(operation, num) { | |
| if (num <= 0) return | |
| operation() | |
| // release control every 10 or so | |
| // iterations. | |
| // 10 is arbitrary. | |
| if (num % 10 === 0) { | |
| setTimeout(function() { | |
| repeat(operation, --num) | |
| }) | |
| } else { | |
| repeat(operation, --num) | |
| } | |
| } | |
| module.exports = repeat |
This file contains hidden or 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
| function repeat(operation, num) { | |
| setTimeout(function () { | |
| if (num <= 0) return | |
| operation() | |
| return repeat(operation, --num) | |
| }) | |
| } | |
| module.exports = repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment