async-method

Makes async methods work with callbacks and promises

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
async-method
011.0.04 years ago8 years agoMinified + gzip package size for async-method in KB

Readme

async-method
Makes async methods work with callbacks and promises. You have a function on your class that expects a callback as last parameter? Wrap it using the asyncMethod and it returns a promise if the callback is omitted.

installation

npm i async-method

build status

Build Status

usage


// create a class 
var MyClass = new Class({
    multiply: asyncMethod(function(a, b, callback) {
        process.nextTick(function() {
            callback(null, a*b);
        });
    })
});



var myClassInstance = new MyClass();


// classic callback 
myClassInstance.multiply(3, 5, function(err, result) {

});


// es6 promise
myClassInstance.multiply(3, 5).then(function(result) {

}).catch(function(err) {

});