AjaxPoll - Voliware/AjaxPlus GitHub Wiki

Are We There Yet?

Like an annoying child, AjaxPoll will ask the same question indefinitely until it gets what it wants. AjaxPoll is great when trying obtain the result of an operation, and only one result is considered valid. AjaxPoll is an AjaxModule extension that only emits done if the data it received satisfies some condition, and only emits fail if it has given up.

var poll = new AjaxPoll({
    maxPolls : 0, // infinite
    maxFails : 100,
    expectation : 1,
    // all AjaxModule options inherited
    request : Server.didLeafsWin,
    interval : 25000
})
// done event fires if data = expectation (1)
.on('done', function(data){
   app.joinBandwagon(data);
})
// fail event fires if maxPolls or maxFails is reached
.on('fail', function(){
   app.rebuildTeam(true);
})
.start();

We start a poll that only emits a done event if the data in the last request was equal to the expectation option. If the expectation is a value, AjaxPoll will compare the data in the last request's done handler using strict equality comparison. If expectation is a function, you can write your own rules about what is considered a valid value.