Skip to content

Instantly share code, notes, and snippets.

@chapel
Last active December 21, 2015 16:39
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 chapel/311c246c52708ecf8324 to your computer and use it in GitHub Desktop.
Save chapel/311c246c52708ecf8324 to your computer and use it in GitHub Desktop.
var floc = require('./floc');
function doAsync(value, cb) {
setTimeout(function() {
cb(null, value / 2);
}, 1000);
}
var callback = floc(function (err, value) {
this.valueMain = value;
this.one(null, value);
})
.add('one', function(err, value) {
this.valueOne = value;
this.two(null, value * 2);
})
.add('two', function (err, value) {
this.valueTwo = value;
doAsync(value, this.three);
})
.add('three', function (err, value) {
this.valueThree = value;
console.log(this)
})
.set('foo2', 'bar2')
callback(null, 10);
callback(null, 20);
function doAsync(value, cb) {
setTimeout(function() {
cb(null, value / 2);
}, 1000);
}
function callback(err, value) {
var self = {};
self.foo2 = 'bar2';
self.valueMain = value;
one(null, value);
function one(err, value) {
self.valueOne = value;
two(null, value * 2);
}
function two(err, value) {
self.valueTwo = value;
doAsync(value, this.three);
}
function three(err, value) {
self.valueThree = value;
console.log(this);
}
}
callback(null, 10);
callback(null, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment