deferrer

Deferrer is a fast promise-object generator.

deferrer

Deferrer is a fast promise-object generator.

Exmaples

function Foo (){}

Foo.prototype._a = function (args, done) {
    setTimeout(function (){
        console.log('a', args);
        done(null);

    }, 100);
}

Foo.prototype._b = function (args, done) {
    process.nextTick(function(){
        console.log('b', args);
        done(null);
    });
}

Foo.prototype._done = function(err, callback){
    callback(err);
}

var deferrer = require('deferrer');

deferrer({
    host: Foo.prototype
    type: 'parallel'
})
.promise('a', '_a')
.promise('b', '_b')
.done('_done');

var foo = new Foo();

foo.a(1, 2).b(3, 4).done(function(err){
    console.log('done');
});

// b [3, 4]
// a [1, 3]
// done

Repository

https@github.com:kaelzhang/node-deferrer


上一篇:ruglify
下一篇:hum

相关推荐

暂无相关文章

官方社区

扫码加入 JavaScript 社区