Skip to content

Instantly share code, notes, and snippets.

@slavone
Created April 12, 2016 08:53
Show Gist options
  • Save slavone/edf62dc3874d28a89adc38b2837f2237 to your computer and use it in GitHub Desktop.
Save slavone/edf62dc3874d28a89adc38b2837f2237 to your computer and use it in GitHub Desktop.
Basic ajax poller in .coffee
@AjaxPoller = (args) ->
this.controllerUrl = args['controllerUrl']
this.pollBody = args['pollBody']
this.pollWhile = args['pollWhile']
this.interval = args['interval']
this.startPolling = () ->
that = this
$.ajax
url: that.controllerUrl
dataType: 'json'
success: (data) ->
that.pollBody(data)
complete: ->
if that.pollWhile()
setTimeout(that.startPolling.bind(that), that.interval);
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment