rwxr--r--
/dev/blog

Bez Hermoso, Software Engineer @ Square

If for some reason you wish to support both the use of promises and_ Node-like callbacks (eww!), bluebird’s Promise.prototype.asCallback(...) can come in handy:

function myAsyncFunc = function (param, callback) {
    var p = return new Promise(function (resolve, reject) {
        ...
    });
    return p.asCallback(callback);
}

// You can do this:
myAsyncFunc("foo", function (err, result) {
    ...
});

// or you can use it like a promise...
myAsyncFunc("foo")
    .then(function (result) {
        ...
    }, function (err) {
        ...
    });

Both will work.

See bluebird’s asCallback(...)

comments powered by Disqus