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.
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) → {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. If no timeout value is provided or if the provided value is negative, the timer remains disabled until rearmed with a positive timeout value.
Name | Type | Description |
---|---|---|
timeout | number | (optional, default: -1 )Optional. The timeout value in milliseconds until the timer expires. Defaults to -1, which disables the timer until rearmed with a positive timeout. |
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