Class: Timer

Timer()

A Timer provides a mechanism to receive an event after a timeout.

A timer has a set duration, and is either started or stopped at a given time. The timer is initially stopped. When the timer is started, a timeout event is scheduled to fire once the set duration elapses. When the timer is stopped, the scheduled timeout event is cancelled. When a timeout event fires, the timer returns to the stopped state.

Constructor

new Timer()

Parameters:
Name Type Attributes Default Description
opts.duration number <optional>
Infinity

Timeout in milliseconds.

Methods

duration()

Returns the currently set duration.

setDuration(duration)

Sets the duration. If the timer is already started, the timeout event is rescheduled to occur once the new duration has elapsed since the last call to start. In particular, if an amount of time larger than the new duration has already elapsed, the timeout event fires immediately.

Parameters:
Name Type Description
duration number

start()

Starts the timer. If the timer is already started, this has the effect of stopping and starting again (i.e. resetting the timer).

started() → {boolean}

Returns whether the timer is in the started state.

Returns:
Type
boolean

stop()

Stops the timer.

Events

timeout

Signals a timeout.