Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Wardormeur/eec5a9df20973eb73333e2a0b03b82bf to your computer and use it in GitHub Desktop.
Save Wardormeur/eec5a9df20973eb73333e2a0b03b82bf to your computer and use it in GitHub Desktop.
module.exports = function math(options) {
this.add('role:math,cmd:sum', function sum(msg, respond) {
respond(null, { answer: msg.left + msg.right })
})
this.add('role:math,cmd:product', function product(msg, respond) {
respond(null, { answer: msg.left * msg.right })
})
this.add('role:ope, cmd:addOne', function addOne(msg, done){
msg.left = Number(msg.msg.left).valueOf()+1;
msg.right = Number(msg.msg.right).valueOf()+1;
done(null, msg);
});
this.wrap('role:math', function (msg, respond) {
this.act({role :'ope', cmd:'addOne', msg: msg}, function(err, out){
msg.left = out.left;
msg.right = out.right;
console.log('msg.left', out.left);
this.prior(msg, respond);
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment