callback-and-promise
make generic async function return promise when callback not present.
- Supports both callback and promise
- 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
Installation
$ npm install callback-and-promise --save
Usage
Examples
- Promisifies a single function:
var promisify = ; var somethingAsync = ; // return a promise when callback not present; // common async style;
- Promisifies all the selected functions in an object:
var promisifyAll = ; var fs = ; fs;
APIs
var fn = promisify([name], fn)
name
- custom function namefn
- the source function
var obj = promisifyAll(source, [obj], [methods])
source
- the source object for the async functionsobj
- the destination to set all the promisified methodsmethods
- an array of method names of source
License
MIT