Timeout Object
var TIMER = new Timeout(function(){ alert("Timeout") }, 10000);
This object is like the inbuilt 'setTimeout' but allows for pause, resume and reset operations as well as querying the remaining time.
The code can be obtained from the head of this document. View source in your browser.
var TIMER = new Timeout( [<action:coderef>, [<period:integer>, [<start:boolean>]]] );
The constructor takes optional parameters of the function to call when the period finishes, and a boolean indicating if we should start immediately
var integer = TIMER.remainingTime()
Returns the time remaining on the timeout in thousandths of a second
TIMER.setAction( <function:coderef> )
Sets (or changes) the function that will be called when time is up
TIMER.setTime( <period:integer> )
Sets (or changes) the period for the timeout in thousandths of a second. If the timeout is currently in progress, the timer will be reset (but not paused).
TIMER.start()
TIMER.reset()
start and reset are synonomous functions for starting the Timeout from the original period value
TIMER.pause()
Pauses execution of the function indefinitely
TIMER.resume()
Resumes a timeout from the pause, or if the timeout isn't in progress, from the original period value.
TIMER.clear()
Clears any pause without resuming. Calling resume() after this will be the same as calling start() or reset().
Support for this function is provided via ##javascript on freenode IRC.
Bugs, errors and omissions excepted and accepted.
Copyright © Rick Measham, 2007. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the GPL or under the same terms as Perl at your discresion.
Rick Measham (aka Woosta)