Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Remove throttle in favor of retry
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtextrem committed Jun 15, 2014
1 parent 711a192 commit 87a495b
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@
'9': 'Woodman',
}

function throttle(fn, scope, delay) {
var last, deferTimer, count
return function () {
var context = scope, now = +new Date, args = arguments;
if (last && now < last + threshhold) {
count++
clearTimeout(deferTimer)
deferTimer = setTimeout(function () {
last = now
fn.apply(context, args)
}, delay * count * 1000)
} else {
count = 0
last = now
fn.apply(context, args)
}
}
}

var Alert = function () {
this.addListener()
}
Expand All @@ -57,6 +38,7 @@
alert: false,
timeRemind: 30,
alwaysRemind: false,
errorDelay: 2,

init: function (force, callback) {
chrome.storage.local.get({
Expand Down Expand Up @@ -100,8 +82,9 @@

qwest.post(this.url, {ref: 'kurtextrem alert monitor'}, { dataType: 'json' }).success(function(data) {
if (!data) {
// same as error API error U
window.setTimeout(this.update.bind(this), ++this.errorDelay * 2000)
}
this.errorDelay = 2

var server, length = Object.keys(data).length - 1
for (var i = 0; i < length; i++) {
Expand All @@ -121,7 +104,9 @@

chrome.storage.local.set({ servers: this.servers, count: this.count, serverTimestamp: Date.now() })
this.updateIcon()
}.bind(this)).error(throttle(this.update(), this, 2))
}.bind(this)).error(function() {
window.setTimeout(this.update.bind(this), ++this.errorDelay * 2000)
}.bind(this))
},

sendToPopup: function (server) {
Expand Down

0 comments on commit 87a495b

Please sign in to comment.