Created
January 15, 2015 11:21
-
-
Save shubhendusaurabh/96b717a1df5e19fc0c40 to your computer and use it in GitHub Desktop.
Synchronous
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 synchronously(tasks){ | |
var i, task, func, | |
promise = $.Deferred().resolve().promise(), // | |
makeRunner = function(func, args){ // | |
return function(){ | |
return func.apply(null, args).promise(); | |
}; | |
}; | |
for (i = 0; i < tasks.length; i++){ | |
task = tasks[i]; | |
func = task.shift(); | |
promise = promise.then(makeRunner(func, task)); // | |
} | |
return promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment