Created
April 11, 2017 07:50
-
-
Save guidone/ed3eccae5f2929414d81edc1a10a093c to your computer and use it in GitHub Desktop.
Poller
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 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