Created
December 17, 2013 14:23
-
-
Save nadinengland/8005636 to your computer and use it in GitHub Desktop.
Queuing Deferred Tasks
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
var Queue = function () { | |
var previous = new $.Deferred().resolve(); | |
return function (fn, fail) { | |
return previous = previous.then(fn, fail || fn); | |
}; | |
}; |
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
var queue = Queue(); | |
var values = [...]; | |
values.forEach(function (value) { | |
queue(function () { | |
return $.post('/', value); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment