Created
May 30, 2012 18:29
-
-
Save omerucel/2838147 to your computer and use it in GitHub Desktop.
seri işlemler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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