1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
4 Copyright 2007, Google Inc.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14 3. Neither the name of Google Inc. nor the names of its contributors may be
15 used to endorse or promote products derived from this software without
16 specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 <title>Timer API
</title>
33 <link rel=
"stylesheet" type=
"text/css" href=
"gears.css" />
40 <div id=
"pagecontent">
42 <p>The Timer module implements the
<a
43 href=
"http://www.whatwg.org/specs/web-apps/current-work/multipage/section-timers.html">WhatWG
44 Timer specification
</a>, and makes it available in both workers and the main
45 HTML page. This is the same timer API that is traditionally available in
46 browsers on the
<code>window
</code> object.
52 <li><a href=
"#overview">Overview
</a>
53 <li><a href=
"#example">Example
</a>
54 <li><a href=
"#timer_class">Timer class
</a>
59 <h2 id=
"overview">Overview
</h2>
61 <p>Since workers don't have access to the window object, they also don't have
62 access to the standard timer functionality. The Timer module exposes similar
63 functionality that can be used both in the main page and in workers. This
64 allows code to be shared across both contexts.
67 <h2 id=
"example">Example
</h2>
69 <pre><code><script
type=
"text/javascript" src=
"<a href='tools.html#gears_init'>gears_init.js</a>"></script
>
70 <script
type=
"text/javascript">
71 var timer = google.gears.factory.create('beta.timer');
72 timer.setTimeout(function() { alert('Hello, from the future!'); },
74 </script
></code></pre>
77 <h2 id=
"timer_class">Timer class
</h2>
79 <pre><code>int
<b>setTimeout
</b>(fullScript, msecDelay)
80 int
<b>setTimeout
</b>(function, msecDelay)
81 int
<b>setInterval
</b>(fullScript, msecDelay)
82 int
<b>setInterval
</b>(function, msecDelay)
83 void
<b>clearTimeout
</b>(timerId)
84 void
<b>clearInterval
</b>(timerId)
</code></pre>
92 <th colspan=
"2"><div align=
"left"><code>setTimeout(function, msecDelay)
</code></div></th>
96 <td class=
"odd"><code>function
</code> <br />
97 <code>msecDelay
</code></td>
100 <td width=
"113">Return value:
</td>
101 <td width=
"489">The ID of the new timeout.
</td>
104 <td>Description:
</td>
106 Creates a timeout that will call
<code>function
</code> after
107 <code>msecDelay
</code> milliseconds have elapsed.
109 Timer IDs are guaranteed to be unique values that are never reused
110 within the same Timer.
116 <th colspan=
"2"><div align=
"left"><code>setTimeout(fullScript, msecDelay)
</code></div></th>
120 <td class=
"odd"><code>fullScript
</code><code> <br />
121 <code>msecDelay
</code></td>
124 <td width=
"113">Return value:
</td>
125 <td width=
"489">The ID of the new timeout.
</td>
128 <td>Description:
</td>
130 Creates a timeout that will evaluate
<code>fullScript
</code>
131 after
<code>msecDelay
</code> milliseconds have elapsed.
133 Timer IDs are guaranteed to be unique values that are never reused
134 within the same Timer.
140 <th colspan=
"2"><div align=
"left"><code>setInterval(function, msecDelay)
</code></div></th>
144 <td class=
"odd"><code>function
</code><code> <br />
145 <code>msecDelay
</code></td>
148 <td width=
"113">Return value:
</td>
149 <td width=
"489">The ID of the new interval.
</td>
152 <td>Description:
</td>
154 Creates an interval that will call
<code>function
</code>
155 after every
<code>msecDelay
</code> milliseconds have elapsed.
156 It will continue to fire until you call clearInterval() with this
157 interval's ID, or the page is unloaded.
159 Timer IDs are guaranteed to be unique values that are never reused
160 within the same Timer.
166 <th colspan=
"2"><div align=
"left"><code>setInterval(fullScript, msecDelay)
</code></div></th>
170 <td class=
"odd"><code>fullScript
</code><code> <br />
171 <code>msecDelay
</code></td>
174 <td width=
"113">Return value:
</td>
175 <td width=
"489">The ID of the new interval.
</td>
178 <td>Description:
</td>
180 Creates an interval that will evaluate
<code>fullScript
</code>
181 after every
<code>msecDelay
</code> milliseconds have elapsed.
182 It will continue to fire until you call clearInterval() with this
183 interval's ID, or the page is unloaded.
185 Timer IDs are guaranteed to be unique values that are never reused
186 within the same Timer.
192 <th colspan=
"2"><div align=
"left"><code>clearTimeout(timeoutId)
</code></div></th>
196 <td class=
"odd"><code>timeoutId
</code>
197 - The ID of the timeout to remove.
201 <td>Description:
</td>
204 created with either the
<code>fullScript
</code> or
205 <code>function
</code> version.
211 <th colspan=
"2"><div align=
"left"><code>clearInterval(intervalId)
</code></div></th>
215 <td class=
"odd"><code>intervalId
</code>
216 - The ID of the interval to remove.
220 <td>Description:
</td>
222 Works with intervals created with either the
223 <code>fullScript
</code> or
<code>function
</code>
224 version. No future events will fire from the given interval.