.. | ||
index.js | ||
LICENSE | ||
package.json | ||
README.md |
thenify
Promisify a callback-based function using any-promise
.
- Preserves function names
- Uses a native promise implementation if available and tries to fall back to a promise implementation such as
bluebird
- Converts multiple arguments from the callback into an
Array
- Resulting function never deoptimizes
- Supports both callback and promise style
An added benefit is that throw
n errors in that async function will be caught by the promise!
API
- Turn async functions into promises
var thenify = require('thenify');
var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
callback(null, a, b, c);
});
- Backward compatible with callback
var thenify = require('thenify').withCallback;
var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
callback(null, a, b, c);
});
// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);
// somethingAsync(a, b, c, function () {});
var fn = thenify(fn)
Promisifies a function.