Represents a uloop timer instance as returned by timer().
const timeout = uloop.timer(…);
timeout.set(…);
timeout.remaining();
timeout.cancel();- Source
- See
Methods
cancel() → {boolean}
Cancels the uloop timer, disarming it and removing it from the event loop.
This method destroys the uloop timer and releases its associated resources. Calling it on a timer that already fired is not required; the timer then only drops its callback and returns false.
Returns true on success.
// Cancel the uloop timer
timer.cancel();- Source
remaining() → {number}
Returns the number of milliseconds until the uloop timer expires.
This method returns the remaining time until the uloop timer expires. If the timer is not armed (i.e., disabled), it returns -1.
The number of milliseconds until the timer expires, or -1 if the timer is not armed.
// Get the remaining time until the uloop timer expires (~500ms)
const remainingTime = timer.remaining();
if (remainingTime !== -1)
printf("Time remaining until timer expires: %d ms\n", remainingTime);
else
printf("Timer is not armed\n");- Source
set(timeoutopt, nullable) → {boolean}nullable
Rearms the uloop timer with the specified timeout.
This method rearms the uloop timer with the specified timeout value, allowing it to trigger after the specified amount of time. A zero or negative timeout expires the timer on the next event loop iteration. If no timeout value or null is provided, the timer is disarmed and keeps its callback, so that a later call can rearm it.
| Name | Type | Description |
|---|---|---|
timeout | number | (optional, nullable) Optional. The timeout value in milliseconds until the timer expires. Without a value, the timer is disarmed. |
Returns true on success, null on error, such as an invalid timeout argument.
const timeout = uloop.timer(…);
// Rearm the uloop timer with a timeout of 1000 milliseconds
timeout.set(1000);
// Disable the uloop timer
timeout.set();- Source