[Author: zork]
[google-gears.git] / gears / sdk / api_timer.html
blob53087581c6b6f2f5e4db11403615af5de33db0ab
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
3 <!--
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.
28 -->
30 <html>
31 <head>
32 <title>Timer API</title>
33 <link rel="stylesheet" type="text/css" href="gears.css" />
34 </head>
36 <body>
38 <h1>Timer API</h1>
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.
49 <h3>Contents</h3>
51 <ol class="toc">
52 <li><a href="#overview">Overview</a>
53 <li><a href="#example">Example</a>
54 <li><a href="#timer_class">Timer class</a>
55 </ol>
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>&lt;script type="text/javascript" src="<a href='tools.html#gears_init'>gears_init.js</a>"&gt;&lt;/script&gt;
70 &lt;script type="text/javascript"&gt;
71 var timer = google.gears.factory.create('beta.timer');
72 timer.setTimeout(function() { alert('Hello, from the future!'); },
73 1000);
74 &lt;/script&gt;</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>
85 <br>
88 <h3>Methods</h3>
90 <table>
91 <tr class="odd">
92 <th colspan="2"><div align="left"><code>setTimeout(function, msecDelay)</code></div></th>
93 </tr>
94 <tr class="odd">
95 <td>Parameters:</td>
96 <td class="odd"><code>function</code> <br />
97 <code>msecDelay</code></td>
98 </tr>
99 <tr class="odd">
100 <td width="113">Return value:</td>
101 <td width="489">The ID of the new timeout.</td>
102 </tr>
103 <tr class="odd">
104 <td>Description:</td>
105 <td class="odd">
106 Creates a timeout that will call <code>function</code> after
107 <code>msecDelay</code> milliseconds have elapsed.
108 <br><br>
109 Timer IDs are guaranteed to be unique values that are never reused
110 within the same Timer.
111 </td>
112 </tr>
113 </table>
114 <table>
115 <tr class="odd">
116 <th colspan="2"><div align="left"><code>setTimeout(fullScript, msecDelay)</code></div></th>
117 </tr>
118 <tr class="odd">
119 <td>Parameters:</td>
120 <td class="odd"><code>fullScript</code><code> <br />
121 <code>msecDelay</code></td>
122 </tr>
123 <tr class="odd">
124 <td width="113">Return value: </td>
125 <td width="489">The ID of the new timeout.</td>
126 </tr>
127 <tr class="odd">
128 <td>Description:</td>
129 <td class="odd">
130 Creates a timeout that will evaluate <code>fullScript</code>
131 after <code>msecDelay</code> milliseconds have elapsed.
132 <br><br>
133 Timer IDs are guaranteed to be unique values that are never reused
134 within the same Timer.
135 </td>
136 </tr>
137 </table>
138 <table>
139 <tr class="odd">
140 <th colspan="2"><div align="left"><code>setInterval(function, msecDelay)</code></div></th>
141 </tr>
142 <tr class="odd">
143 <td>Parameters:</td>
144 <td class="odd"><code>function</code><code> <br />
145 <code>msecDelay</code></td>
146 </tr>
147 <tr class="odd">
148 <td width="113">Return value:</td>
149 <td width="489">The ID of the new interval.</td>
150 </tr>
151 <tr class="odd">
152 <td>Description:</td>
153 <td class="odd">
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.
158 <br><br>
159 Timer IDs are guaranteed to be unique values that are never reused
160 within the same Timer.
161 </td>
162 </tr>
163 </table>
164 <table>
165 <tr class="odd">
166 <th colspan="2"><div align="left"><code>setInterval(fullScript, msecDelay)</code></div></th>
167 </tr>
168 <tr class="odd">
169 <td>Parameters:</td>
170 <td class="odd"><code>fullScript</code><code> <br />
171 <code>msecDelay</code></td>
172 </tr>
173 <tr class="odd">
174 <td width="113">Return value:</td>
175 <td width="489">The ID of the new interval.</td>
176 </tr>
177 <tr class="odd">
178 <td>Description:</td>
179 <td class="odd">
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.
184 <br><br>
185 Timer IDs are guaranteed to be unique values that are never reused
186 within the same Timer.
187 </td>
188 </tr>
189 </table>
190 <table>
191 <tr class="odd">
192 <th colspan="2"><div align="left"><code>clearTimeout(timeoutId)</code></div></th>
193 </tr>
194 <tr class="odd">
195 <td>Parameters:</td>
196 <td class="odd"><code>timeoutId</code>
197 - The ID of the timeout to remove.
198 </td>
199 </tr>
200 <tr class="odd">
201 <td>Description:</td>
202 <td class="odd">
203 Works with timeouts
204 created with either the <code>fullScript</code> or
205 <code>function</code> version.
206 </td>
207 </tr>
208 </table>
209 <table>
210 <tr class="odd">
211 <th colspan="2"><div align="left"><code>clearInterval(intervalId)</code></div></th>
212 </tr>
213 <tr class="odd">
214 <td>Parameters:</td>
215 <td class="odd"><code>intervalId</code>
216 - The ID of the interval to remove.
217 </td>
218 </tr>
219 <tr class="odd">
220 <td>Description:</td>
221 <td class="odd">
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.
225 </td>
226 </tr>
227 </table>
230 </div>
231 </body>
232 </html>