Last active
December 10, 2015 08:08
-
-
Save Raynos/4405251 to your computer and use it in GitHub Desktop.
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
var execute = require("execute") | |
, serial = require("serialize") | |
function add(x, y, cb) { | |
setTimeout(function () { | |
cb(null, x + y) | |
}, 10) | |
} | |
var add4 = serial([ | |
function (a0, a1, a2, a3, cb) { | |
execute({ | |
sum1: function (cb) { add(a0, a1, cb) } | |
, sum2: function (cb) { add(a2, a3, cb) } | |
}, cb) | |
} | |
, function (result, cb) { | |
add(result.sum1, result.sum2, cb) | |
} | |
]) | |
var run = serial([ | |
function (cb) { | |
execute({ | |
sum1: function(cb) { | |
add4(1, 2, 3, 4, cb) | |
} | |
, sum2: function (cb) { | |
add4(5, 6, 7, 8, cb) | |
} | |
}, cb) | |
} | |
, function (result, cb) { | |
add(result.sum1, result.sum2, cb) | |
} | |
]) | |
run(printResult) | |
function printResult(err, result) { | |
if (err) { | |
throw err | |
} | |
console.log("result", result) // prints "result=10" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment