Created
October 21, 2015 18:55
-
-
Save spacepluk/769fe90efa180ca5654c to your computer and use it in GitHub Desktop.
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
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