Timer

Moduleejs
Definition class Timer
InheritanceTimer inherit Object
StabilityPrototype.

Timers manage the execution of functions at some point in the future.

Timers may run once, or they can be scheduled to run repeatedly, until stopped by calling the stop() method. Timers are scheduled with a granularity of 1 millisecond. However, many systems are not capable of supporting this granularity and make only best efforts to schedule events at the desired time.


Properties

QualifiersPropertyTypeDescription
get set driftBooleanThe current drift setting. If drift is true, the timer is allowed to drift its execution time due to other system events when attempting to optimize overall system performance. If the drift value is set to false, the timer is scheduled so that the period between callback start times does not gradually drift. When using non-drifting timers, the timer subsystem will delay other low priority events or timers, if necessary to ensure non-drifting timers are scheduled exactly. 0.
get set onerrorFunctionError callback function for exceptions inside the Timer callback The callback is invoked with the following signature: function callback(error: Error): Void.
get set periodNumberTimer delay period in milliseconds. Changing a timer period will not reschedule a currently scheduled timer. The period will be used to schedule the next invocation. To change the current period, stop the timer and restart it.
get set repeatBooleanTimer repeatability. If true, the timer will be repeated invoked every period milliseconds.

Timer Class Methods

(No own class methods defined)

QualifiersMethod

Timer Instance Methods

QualifiersMethod
Timer(period: Number, callback: Function, args: Array)
 Constructor for Timer.
restart(when: Number = null): Void
 Reschedule a timer.
start(): Timer
 Start a timer running.
stop(): Void
 Stop a timer running.

Method Detail

Timer(period: Number, callback: Function, args: Array)
Description
Constructor for Timer. The timer is will not be called until start is called.
Parameters
period: Number Delay in milliseconds before the timer will run.
callback: Function Function to invoke when the timer is due. The callback is invoked with the following signature: function callback(error: Error): Void.
args: Array Callback arguments.

restart(when: Number = null): Void
Description
Reschedule a timer. This will stop the timer if it is currently scheduled, then reschedule the timer. If the when argument is provided, the timer period will be set before starting.
Parameters
when: Number Time period for when to next run the timer. [default: null]

start(): Timer
Description
Start a timer running. The timer will be repeatedly invoked if the repeat property is true, otherwise it will be invoked once. When the timer callback is invoked, it will be invoked with the value of "this" set to the timer unless the function has bound a "this" value via Function.bind.
Returns
The timer instance. This helps chaining. For example: var timer = Timer(1000, sayHello).start().

stop(): Void
Description
Stop a timer running. Once stopped a timer can be restarted by calling start.