Reputation: 43
If a library exposes a promise-based API that is not based on bluebird but does not expose a traditional callback API, is there a way to "promisify" that library to return bluebird promises?
Currently I either just return the promise to a bluebird context, or if I want to use any bluebird specific functions directly then I wrap the call with bluebird's Promise.resolve.
I believe this would be possible with ES2015 proxies, but neither Node.js™, io.js nor Babel support them.
Is there a sane way to do this without proxies?
Upvotes: 0
Views: 218
Reputation: 140228
Use the promisifier option
Promise.promisifyAll(lib, {
promisifier: function(fn) {
return function () {
return Promise.resolve(fn.apply(this, arguments));
}
}
});
Upvotes: 3