var proback = require('proback');
function fn(throws, cb) {
if (typeof throws === 'function') {
cb = throws;
throws = null;
}
cb = cb || proback();
setTimeout(function () {
if (throws) {
cb(throws);
} else {
cb();
}
});
return cb.promise;
}
fn(function () {
console.log('callback done', arguments);
});
fn('abc', function () {
console.log('callback done', arguments);
});
fn().then(function () {
console.log('promise resolved', arguments);
});
fn('def').catch(function () {
console.log('promise reject', arguments);
});
function fnResolveWithMultiArgs(cb) {
cb = cb || proback();
setTimeout(function () {
cb(null, 1, 2, 3);
});
return cb.promise;
}
fnResolveWithMultiArgs().then(function (data) {
console.log(data);
});
fnResolveWithMultiArgs().spread(function (a, b, c) {
console.log(a, b, c);
});