aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pollymer.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/pollymer.js b/pollymer.js
index 05d3189..96755ed 100644
--- a/pollymer.js
+++ b/pollymer.js
@@ -223,6 +223,7 @@
this.rawResponse = false;
this.maxTries = 1;
this.maxDelay = 1000;
+ this.minDelay = 0;
this.recurring = false;
this.withCredentials = false;
this.timeout = 60000;
@@ -244,6 +245,9 @@
if ("maxDelay" in config) {
this.maxDelay = config.maxDelay;
}
+ if ("minDelay" in config) {
+ this.minDelay = config.minDelay;
+ }
if ("recurring" in config) {
this.recurring = config.recurring;
}
@@ -276,7 +280,13 @@
var delayTime;
if (this._delayNext) {
this._delayNext = false;
- delayTime = Math.floor(Math.random() * this.maxDelay);
+ var delayGap = this.maxDelay - this.minDelay;
+ if (delayGap > 0) {
+ delayTime = this.minDelay + Math.floor(Math.random() * delayGap);
+ } else {
+ delayTime = this.minDelay;
+ }
+
consoleInfo("pollymer: polling again in " + delayTime + "ms");
} else {
delayTime = 0; // always queue the call, to prevent browser "busy"