Timer
Module | ejs |
Definition | class Timer |
Inheritance | Timer Object |
Stability | Prototype. |
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
Qualifiers | Property | Type | Description |
---|---|---|---|
get set | drift | Boolean | The 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 | onerror | Function | Error callback function for exceptions inside the Timer callback The callback is invoked with the following signature: function callback(error: Error): Void. |
get set | period | Number | Timer 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 | repeat | Boolean | Timer repeatability. If true, the timer will be repeated invoked every period milliseconds. |
Timer Class Methods
Qualifiers | Method |
---|
Timer Instance Methods
Qualifiers | Method |
---|---|
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
- Description
- Constructor for Timer. The timer is will not be called until start is called.
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.