promise-wrap
v0.1.0
Published
An incredibly easy way to use promises instead of callbacks, as long as they follow standard node callback conventions
Downloads
2
Maintainers
Readme
promise-wrap
Have you ever wished that something were just wrapped in a promise?
somethingThatRequiresACallback(function(err, data) {
if (err) {
//handle error
}
//do useful stuff
}
Now it is:
var pw = require('promise-wrap');
pw(somethingThatRequiresACallback).then(function(data) {
//do useful stuff
}).error(function(err) {
//handle error
});
Context
By default promise-wrap
will .apply
the first argument with a null context and use the rest as parameters.
If you want to specify a context simply pw.withContextAndArguments(call, context, args...)
Chaining
Very soon there will be support for setting up methods for chaining so that you can
var pw = require('promise-wrap');
somePromise()
.then(pw.chain(somethingThatRequiresACallback))
.then(function(data) {
//do useful stuff
}).error(function(err) {
//handle error
});