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.