Skip to content

Instantly share code, notes, and snippets.

@Raynos
Last active December 10, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/4405251 to your computer and use it in GitHub Desktop.
Save Raynos/4405251 to your computer and use it in GitHub Desktop.
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