thenify
![Downloads](http://img.shields.io/npm/dm/thenify.svg?style=flat-square)
Promisify a callback-based function.
- Preserves function names
- Uses a native promise implementation if available and tries to fall back to
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);
});
var fn = thenify(fn)
Promisifies a function.