promise.cb
v0.0.2
Published
transform an async function to callback style
Downloads
4
Maintainers
Readme
promise.cb
transform an async function to callback style
Install
npm i promise.cb --save
API
const pcb = require('promise.cb');
const cbFn = pcb(asyncFn);
Example
const pcb = require('promise.cb');
async function fn1 (){
return 1
}
const fn2 = require('co').wrap(function*(){
return 2;
});
function fn3(){
return Promise.resolve(3);
}
const _fn1 = pcb(fn1);
const _fn2 = pcb(fn2);
const _fn3 = pcb(fn3);
const cb = (err, res) => {
assert(!err);
console.log(res);
};
_fn1(cb); // log 1
_fn2(cb); // log 2
_fn3(cb); // log 3
Changelog
See Also
Why
callbackify
looks good, but it's usingasyncFn.length
, so it's not working when usingco.wrap
catch(e => cb(e))
is not right, ifcb(e)
throws, it will only cause the promise reject, not throw error up
License
the MIT License http://magicdawn.mit-license.org