You must use ES6 (which support Promise
), that's almost supported.
We don't require more. (^_^)
Install
npm install --save callback-2-promise
Code example:
var C2P = require('callback-2-promise');
function veryLongRun(callback) {
// Your stuffs...
setTimeout(callback, 5000);
}
var c2p = new C2P();
veryLongRun(c2p.getFulfillCallback()); // Get success callback, and pass to your function
var promise = c2p.go(); // Get Promise, you can use `.then()` or `.catch()`
Fulfill callback will call when the task success
- No params
- Return callback
function ([any object] result)
.
Error callback will call when the task failure with an error
- No params
- Return callback
function ([any object] error)
.
Pair callback merge ErrorCallback and FulfilCallback.
- No params
- Return callback
function ([any object] error, [any object] result)
. Iferror = null
, resolve, otherwise reject.