The Timer module implements the WhatWG
Timer specification, and makes it available in both workers and the main
HTML page. This is the same timer API that is traditionally available in
browsers on the window
object.
Since workers don't have access to the window object, they also don't have access to the standard timer functionality. The Timer module exposes similar functionality that can be used both in the main page and in workers. This allows code to be shared across both contexts.
Does not require user permission.
<script type="text/javascript" src="gears_init.js"></script>
<script type="text/javascript">
var timer = google.gears.factory.create('beta.timer');
timer.setTimeout(function() { alert('Hello, from the future!'); },
1000);
</script>
int setTimeout(fullScript, msecDelay)
int setTimeout(function, msecDelay)
int setInterval(fullScript, msecDelay)
int setInterval(function, msecDelay)
void clearTimeout(timerId)
void clearInterval(timerId)
setTimeout(function, msecDelay) |
|
---|---|
Parameters: | function msecDelay |
Return value: | The ID of the new timeout. |
Description: |
Creates a timeout that will call function after
msecDelay milliseconds have elapsed.
Timer IDs are guaranteed to be unique values that are never reused within the same Timer. |
setTimeout(fullScript, msecDelay) |
|
---|---|
Parameters: | fullScript |
Return value: | The ID of the new timeout. |
Description: |
Creates a timeout that will evaluate fullScript
after msecDelay milliseconds have elapsed.
Timer IDs are guaranteed to be unique values that are never reused within the same Timer. |
setInterval(function, msecDelay) |
|
---|---|
Parameters: | function |
Return value: | The ID of the new interval. |
Description: |
Creates an interval that will call function
after every msecDelay milliseconds have elapsed.
It will continue to fire until you call clearInterval() with this
interval's ID, or the page is unloaded.
Timer IDs are guaranteed to be unique values that are never reused within the same Timer. |
setInterval(fullScript, msecDelay) |
|
---|---|
Parameters: | fullScript |
Return value: | The ID of the new interval. |
Description: |
Creates an interval that will evaluate fullScript
after every msecDelay milliseconds have elapsed.
It will continue to fire until you call clearInterval() with this
interval's ID, or the page is unloaded.
Timer IDs are guaranteed to be unique values that are never reused within the same Timer. |
clearTimeout(timeoutId) |
|
---|---|
Parameters: | timeoutId
- The ID of the timeout to remove.
|
Description: |
Works with timeouts
created with either the fullScript or
function version.
|
clearInterval(intervalId) |
|
---|---|
Parameters: | intervalId
- The ID of the interval to remove.
|
Description: |
Works with intervals created with either the
fullScript or function
version. No future events will fire from the given interval.
|