1.0.6 • Published 9 years ago

flatq v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

FlatQ

=========

like q/async

test case will coming soon... more function will coming soon...

用于实现异步的流程同步执行

Download

Check out https://github.com/microlv/FlatQ.git

for details over the differences between builds.

GitHub: https://github.com/microlv/FlatQ/ Wiki: http://microlv.github.io/FlatQ

Features

like q/async, but the code is simple and powerful and useful.

every function will inject a argument name 'defer', you can use it to resolve/reject. or detect the defer.err to see parent function has error or not.

Support

Chrome, Nodejs

Installation

npm install flatq --save

Usage

sample use:

$q(function (d) {
	setTimeout(function () {
		console.log('function 1');
		d.resolve('pass data to next function!');
		console.log('function 1 step 2');
	}, 0);
	console.log('function 1 step 1');
}).then(function (d, data) {
	console.log('function 2');
	console.log(data);
	d.reject();
}).then(function () {
	console.log('function 3,function2 resolve will go here');
}, function () {
	console.log('function 3 function2 reject will go here');
}).then(function () {
	console.log('function 4');
});

series:

$q.series([function(d){
	use resolve will make the series execute next task!
	d.resolve();

	//step pass data
	var passData={hello:'world'};
	d.resolve(passData)

	reject will make series stop.
	d.reject();

}],function(d,data){

	I can get the data from //step pass data
	console.log(data);
});

series example:

$q.series([
	function (d) {
		console.log('series 1');
		setTimeout(function () {
			d.resolve('series 2 finish!');
		}, 0);
	},
	function (d) {
		console.log('series 2');
		setTimeout(function () {
			d.resolve('series 2 finish!');
		}, 0);
	},
	function (d) {
		console.log('series 3');
		setTimeout(function () {
			d.resolve('series 3 finish!');
		}, 0);
	}
], function (d,result) {
	console.log('finish');
	d.resolve();
}).then(function (d) {
	console.log('then start');
});

Author

Andy.lv@live.com; Any problem contact with me.

Contributors