Change code to wind down checks when no doing anything

This commit is contained in:
KodeStar
2018-02-08 19:50:01 +00:00
parent b910a933fb
commit 79f4a6cc07
3 changed files with 29 additions and 12 deletions

10
public/js/app.js vendored
View File

@@ -21,15 +21,21 @@ $.when( $.ready ).then(function() {
$('.livestats-container').each(function(index){
var id = $(this).data('id');
var container = $(this);
(function worker() {
var max_timer = 30000;
var timer = 1000;
(function worker() {
$.ajax({
url: '/get_stats/'+id,
success: function(data) {
container.html(data);
if(data != '') timer = 1000;
else {
if(timer < max_timer) timer += 2000;
}
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(worker, 5000);
setTimeout(worker, timer);
}
});
})();