Package Exports
- thenify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (thenify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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.