Skip to content

Instantly share code, notes, and snippets.

@guidone
Created April 11, 2017 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidone/ed3eccae5f2929414d81edc1a10a093c to your computer and use it in GitHub Desktop.
Save guidone/ed3eccae5f2929414d81edc1a10a093c to your computer and use it in GitHub Desktop.
Poller
var poller = new Poller();
poller.intervals([1000, 5000, 10000])
.checkback(function(callback) {
  // could be anything asynchronous
  $.getJSON('/is/server/ready', function(response) {
  if (response.ready) {
  callback(true);
} else {
  else callback(false);
  }
 })
 .callback(function() {
  // checkback succeded and the end of one interval
  // stops the poller and callback
  console.log('Ok')
 })
 .failback(function() {
  // after the third attempt, exits calling the failback
  // function
  console.log('Failed');
 })
 .start(); // start the process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment