Nodeify
Convert promised code to use node style callbacks. If no callback is provided it will just return the original promise.
Installation
Server:
$ npm install nodeify
Usage
Functional
Call nodeify
directly passing the promise
and an optional callback
as arguments. If a callback
is provided it will be called as callback(error, result)
. If callback
is not a function, promise
is returned.
var nodeify = ; { return ;}
Constructor / Method
The nodeify.Promise
constructor returns a promise with a .nodeify
method which behaves just like the functional version above except that the first argument is implicitly this
.
var Promise = Promise; { return { //do async work } ;}
Extend
Extend(promise)
Takes a promise and extends it to support the .nodeify
method. It will still support the nodeify method after calls to .then
.
var Promise = ;var nodeify = ; { return nodeify ;}
Extend(PromiseConstructor)
Takes a PromiseConstructor and extends it to support the .nodeify
method.
var PromiseConstructor = ; ; { return ;}
Extend()
Extends the default promise constructor (returned by calling require('promise')
) and extends it to support .nodeify
.
; { //assuming myPromiseMethod uses `promise` as its promise library return ;}
Licence
MIT