Simple timer handling.
Does little more than wrap the standard API but keeps hold of the timeout entity.
Creates and configures a new timer.
config should be an object with the following:
ms: the delay after which the function should be calledfn: the function to callrepeat: if truthy, the timer should repeat everymsinactive: if truthy, it only configures without starting
It can also accept the convenience properties:
after: themsvalue and setsrepeattofalseevery: themsvalue and setsrepeattotrueat: sets themsto fire at the given time, withrepeatset to false
If no configuration is given, an inactive default is created which can be re-configured later.
Note: The underlying timer cannot accept a timeout of more than 2^31-1 ms.
Or about 24 days. This can, and will wake every ~24 days until it is due.
As a result it can accept Infinity as a ms setting.
Reconfigures the timer with new settings in the same way as new Timer
Any active timer is cancelled.
Enumerable & read only. The current millisecond setting
Enumerable & read only. The current function to call
Enumerable & read only. The current repeat setting
Cancels the timer. Returns itself for chaining. Idempotent.
Restarts the timer. Returns itself
Is the timer currently active.
When is the timer next due. If ms was set to Infinity, or the timer
is not active, returns undefined
When was the timer last started, or undefined if not active
Returns a promise which will be resolved on the next timer callback.
If the timer is cancelled, then the promise will be rejected.
If the timer is inactive, then you'll simply get a resolved one.
If in node and active, unref's the timer. Benign in the browser. Returns itself for chaining. This setting is maintained through repeats and manual refreshes
The opposite of .unref. Safe in the browser.
Manually fires the timer immediately, if active.