Skip to content

Instantly share code, notes, and snippets.

@cuipengfei
Last active December 31, 2015 09:49
Show Gist options
  • Select an option

  • Save cuipengfei/7969763 to your computer and use it in GitHub Desktop.

Select an option

Save cuipengfei/7969763 to your computer and use it in GitHub Desktop.
functional js blocking event loop
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
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