Search:
Class o2.Timer
static
class
o2.Timer
Function Summary
Sets and optionally starts a new timer.
Usage example:
o2.Timer.set('myTimer', function() {
console.log('hello');
}, 1000, {repeat : true});
Starts/restarts the timer with the given id.
Usage example:
o2.Timer.start('myTimer');
Function Details
function set
Sets and optionally starts a new timer.
Usage example:
o2.Timer.set('myTimer', function() {
console.log('hello');
}, 1000, {repeat : true});
Parameters:
id
- a unique identifier for the timer.
delegate
- action to be done when the timer ticks.
timeout
- interval of the timer in milliseconds.
option
- optional configuration in the form
{start: true, repeat: true}, if start
is true timer will start after being set; otherwise
it should be explicitly started using the
o2.Timer.start method. If repeat is
false the delegate will be executed only once, othwerwise
it will be executed at each interval until o2.Timer.stop
is called. function start
static
start(String
id)
Starts/restarts the timer with the given id.
Usage example:
o2.Timer.start('myTimer');
Parameters:
id
- the id of the timer to start. function stop
static
stop(String
id)
Stops the timer with the given id.
Usage example:
o2.Timer.stop('myTimer');
Parameters:
id
- the id of the timer to stop.
A class for executing repeated timed actions.
Usage example:
// A unique id for the timer. var kCheckId = 'my_timer'; // Auto start timer with id kCheckId to repeat doStuff approximately // every 500 milliseconds, please note that this is an approximation. // for further details see John Resig's excellent article on this: // http://ejohn.org/blog/how-javascript-timers-work/ o2.Timer.set(kCheckId, doStuff, 500, {start: true, repeat: true}); // Stops the timer (i.e. doStuff will not be executed further). o2.Timer.stop(kCheckId); // Restarts the timer (i.e. doStuff will be periodically executed again). o2.Timer.start(kCheckId);