Skip to content

Instantly share code, notes, and snippets.

@hackhat
Created March 20, 2015 10:12
Show Gist options
  • Save hackhat/59cc74d88cc519997f8d to your computer and use it in GitHub Desktop.
Save hackhat/59cc74d88cc519997f8d to your computer and use it in GitHub Desktop.
Reusable services
// api/v1/group/a.js
module.exports = function(args, cb, session){
var bRes = this.f_api('v1.group.b', {
a: 5
}).wait();
cb(void 0, {
myData: bRes.someData
});
}
module.exports.fibers = true;
// api/v1/group/b.js
module.exports = function(args, cb, session){
var cRes = this.f_api('v1.group.c', {
b: args.a * 2 // Now we pass 5 * 2 = 10
}).wait();
cb(void 0, {
someData: cRes.c
});
}
module.exports.fibers = true;
// api/v1/group/c.js
module.exports = function(args, cb, session){
cb(void 0, {c: args.b * 2}); // 10 * 2 = 20;
}
module.exports.fibers = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment