run-all-sync

1.0.2 • Public • Published

Execute functions one by one

runAllSync accepts n number of functions. The last function is the callback. All the functions before the last one will execute one by one. On call of cb which is passed as a argument to every function the next function will execute. If there is an error call the cb with an argument otherwise without argument. The last callback function will be executed when all the functions before it gets executed or some functions calls cb with an argument. Check the callback if there is an error

var runAllSync = require('run-all-sync');

runAllSync(function(cb){
	setTimeout(function(){
		console.log(1);
		cb();
	}, 200);
}, function(cb){
	console.log(2);
	cb("some error");
}, function(cb){
	setTimeout(function(){
		console.log(3);
		cb();
	}, 200);
}, function(err){
	if(err){
		return console.log(err);
	}
	console.log("Success");
});

output: 1 2 some error

/run-all-sync/

    Package Sidebar

    Install

    npm i run-all-sync

    Weekly Downloads

    2

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    3.2 kB

    Total Files

    4

    Last publish

    Collaborators

    • jaman