Skip to content

Instantly share code, notes, and snippets.

@ekorneeff
Last active December 15, 2015 13:49
Show Gist options
  • Save ekorneeff/5270317 to your computer and use it in GitHub Desktop.
Save ekorneeff/5270317 to your computer and use it in GitHub Desktop.
ajax queue for js
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