In a promise library bluebird have function promisifyAll or other similar libraries that claim to convert async functions with callback patterns into promise based ie. resolve()
, reject()
, or done()
..So how does it work?
For example:
function myAsync1 (data, url, callBack) {...}
and if i put it in
Promise.promisify(myAsycn1);
then will my function work like this..
myAsync1('{..}', 'http://..').then(function(){...});
This is have been bothering me. Is there a pattern that async non promise libs or function need to follow for Bluebird promisifyAll to convert them to promises based methods or there is some magic that converts them.
If not then what are the requirements and how does it work with existing libraries like mongodb etc.
Promise.promisify
does return a new function that will call the old with the callback. – Thorin