Last active
December 15, 2015 13:49
-
-
Save ekorneeff/5270317 to your computer and use it in GitHub Desktop.
ajax queue for js
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
class AjaxQueue | |
@MAX = 40 | |
constructor: () -> | |
@requests = [] | |
@current = 0 | |
ajax: (opts) -> | |
opts.complete = (jqXHR, textStatus) => | |
@current -= 1 | |
@send() | |
@requests.push(opts) | |
@send() | |
send: () -> | |
while @current < AjaxQueue.MAX && @requests.length > 0 | |
$.ajax(@requests.unshift()) | |
@current += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment