File: timeout.js

package info (click to toggle)
greasemonkey 2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,820 kB
  • sloc: xml: 171; makefile: 10
file content (24 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Components.utils.import('resource://greasemonkey/util.js');

const EXPORTED_SYMBOLS = ['timeout'];

function timeout(aCallback, aDelay, aType) {
  var type = aType;
  if ('undefined' == typeof type) {
    type = Components.interfaces.nsITimer.TYPE_ONE_SHOT;
  }

  // Create the timer object.
  var timer = Components.classes["@mozilla.org/timer;1"]
      .createInstance(Components.interfaces.nsITimer);
  // Init the callback, with a closure reference to the timer, so that it is
  // not garbage collected before it fires.
  timer.init(
      {
        'observe': function() {
          timer;  // Here's the reference that keeps the timer alive!
          aCallback();
        }
      },
      aDelay, type);
}