From c9b191e192df838097797b82ad86b667555c994a Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 22 Mar 2015 09:26:10 +0000 Subject: Add minDelay option --- pollymer.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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" -- cgit v1.2.3