I am playing with microservices using Seneca library. Here is a microservice that adds two numbers, plus a client using it. This example comes directly from the Getting started page
1 | var seneca = require('seneca')(); |
I love the simplicity, but hate the callbacks. So I promisify the seneca.add
using
Bluebird library. Typically, one can
convert all methods attached to an object using Promise.promisifyAll. In this case,
notice that some seneca
methods are not asynchronous. For example, seneca.add
has Node-style
looking callback, but it is just an event listener, not a response callback.
So I converted the seneca.act
method only
1 | var seneca = require('seneca')(); |
Notice that we are calling the actAsync
function using <object>.<method>
notation.
Thus we do NOT need to attach the promisifed method to the seneca
object.
1 | seneca.actAsync = Promise.promisify(seneca.act); |
We saved a couple of characters and a whole variable.