Requires

Provides

Request.Periodical.js

Requests the same URL to pull data from a server but increases the intervals if no data is returned to reduce the load

License:
MIT-style license
Authors:
Christoph Pojer
  1. 25
  2. 26
  3. 27
  4. 28
  5. 29
  6. 30
  7. 31
  8. 32
  9. 33
  10. 34
  11. 35
  12. 36
  13. 37
  14. 38
  15. 39
  16. 40
  17. 41
  18. 42
  19. 43
  20. 44
  21. 45
  22. 46
  23. 47
  24. 48
  25. 49
  26. 50
  27. 51
  28. 52
Request.implement({ options: { initialDelay: 5000, delay: 5000, limit: 60000 }, startTimer: function(data){ var fn = function(){ if (!this.running) this.send({data: data}); }; this.lastDelay = this.options.initialDelay; this.timer = fn.delay(this.lastDelay, this); this.completeCheck = function(response){ clearTimeout(this.timer); this.lastDelay = (response) ? this.options.delay : (this.lastDelay + this.options.delay).min(this.options.limit); this.timer = fn.delay(this.lastDelay, this); }; return this.addEvent('complete', this.completeCheck); }, stopTimer: function(){ clearTimeout(this.timer); return this.removeEvent('complete', this.completeCheck); } });