Skip to content

Instantly share code, notes, and snippets.

@spacepluk
Created October 21, 2015 18:55
Show Gist options
  • Save spacepluk/769fe90efa180ca5654c to your computer and use it in GitHub Desktop.
Save spacepluk/769fe90efa180ca5654c to your computer and use it in GitHub Desktop.
testfn = (s) => () => console.log(s)
var chunkedProcess = [1, 2, 3, 4, 5, 6, 7].map(testfn)
function spreadProcess(fns) {
process.nextTick(fns.reduceRight(function (prev, next) {
return function() {
next()
process.nextTick(() => prev())
}
}))
}
spreadProcess(chunkedProcess)
// This is equivalent to
//
// process.nextTick(function() {
// console.log(1)
// process.nextTick(function() {
// console.log(2)
// process.nextTick(function() {
// console.log(3)
// process.nextTick(function() {
// // ...
// })
// })
// })
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment