deferrer

2019-10-12 admin

deferrer是什么

什么是deferrer,Deferrer is a fast promise-object generator.

deferrer使用教程帮助文档

deferrer NPM version Build Status Dependency Status

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

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-77186.html

文章标题:deferrer

回到顶部