Skip to content

Instantly share code, notes, and snippets.

@omerucel
Created May 30, 2012 18:29
Show Gist options
  • Save omerucel/2838147 to your computer and use it in GitHub Desktop.
Save omerucel/2838147 to your computer and use it in GitHub Desktop.
seri işlemler
function Senkron(functions , resultCallback)
{
var index = -1;
var size = functions.length;
var callback = function(err){
if (err)
return resultCallback(err);
if (++index == size)
return resultCallback();
try
{
(functions[index])(callback);
}catch(e){
resultCallback(e);
}
};
callback();
}
Senkron([
function(callback){
setTimeout(function(){
console.log(1);
callback(null);
}, 15);
},
function(callback){
console.log(2);
callback(null);
},
function(callback){
setTimeout(function(){
console.log(3);
callback(null);
}, 50);
},
function(callback){
setTimeout(function(){
console.log(4);
callback(null);
}, 10);
}
], function(err){
console.log("ERROR : ", err);
console.log("END");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment