CREDITS: update
[conkeror/arlinius.git] / modules / timer.js
blobe0257937a6181e015b1b02d01990ead88e45923b
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 function timer_callback (callback) {
9     this.callback = callback;
11 timer_callback.prototype = {
12     constructor: timer_callback,
13     QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback]),
15     notify: function (timer) {
16         this.callback.call(null, timer);
17     }
20 function call_after_timeout (callback, timeout) {
21     var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
22     timer.initWithCallback(new timer_callback(callback), timeout, Ci.nsITimer.TYPE_ONE_SHOT);
23     return timer;
26 function call_at_interval (callback, interval) {
27     var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
28     timer.initWithCallback(new timer_callback(callback), interval, Ci.nsITimer.TYPE_REPEATING_SLACK);
29     return timer;
32 function call_at_precise_interval (callback, interval) {
33     var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
34     timer.initWithCallback(new timer_callback(callback), interval, Ci.nsITimer.TYPE_REPEATING_PRECISE);
35     return timer;
38 function timer_cancel (timer) {
39     timer.cancel();
42 provide("timer");