aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2015-03-22 09:26:10 +0000
committerChristopher Baines <mail@cbaines.net>2015-03-22 09:26:10 +0000
commitc9b191e192df838097797b82ad86b667555c994a (patch)
treedad2c2beeab00f4b47ee3255ec340db20030d91c
parent16c672b6357040a60ab83de29475eb8b72998df7 (diff)
downloadpollymer-master.tar
pollymer-master.tar.gz
Add minDelay optionHEADmaster
-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"