CodeOfficer (owner)

Fork Of

Revisions

gist: 158622 Download_button fork
public
Public Clone URL: git://gist.github.com/158622.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* a smart poller for jquery.
* (by github)
*
* simple example:
*
* $.smartPoller(function(retry) {
* $.getJSON(url, function(data) {
* if (data) {
* doSomething(data)
* } else {
* retry()
* }
* })
* })
*
* The $.smartPoller function accepts a starting
* interval in ms but defaults to 1000:
*
* $.smartPoller(2000, function(retry) {
*
*/
 
;(function($) {
  $.smartPoller = function(wait, poller) {
    if ($.isFunction(wait)) {
      poller = wait
      wait = 1000
    }
 
    (function startPoller() {
      setTimeout(function() {
        poller.call(this, startPoller)
      }, wait)
      wait = wait * 1.5
    })()
  }
})(jQuery);