Represents a uloop interval timer instance as returned by interval().
const intv = uloop.interval(…);
intv.set(…);
intv.remaining();
intv.expirations();
intv.cancel();- Source
- See
Methods
cancel() → {boolean}
Cancels the uloop interval.
This method cancels the uloop interval, disarming it and removing it from the event loop. Associated resources are released.
Returns true on success.
// Cancel the uloop interval
interval.cancel();- Source
expirations() → {number}
Returns number of times the interval timer fired.
This method returns the number of times the uloop interval timer has expired (fired) since it was instantiated.
The number of times the uloop interval timer has expired (fired).
// Get the number of times the uloop interval timer has expired
const expirations = interval.expirations();
printf("Number of expirations: %d\n", expirations);- Source
remaining() → {number}
Returns the milliseconds until the next expiration.
This method returns the remaining time until the uloop interval expires and triggers again. If the interval is not armed (i.e., disabled), it returns -1.
The milliseconds until the next expiration of the uloop interval, or -1 if the interval is not armed.
// Get the milliseconds until the next expiration of the uloop interval
const remainingTime = interval.remaining();
if (remainingTime !== -1)
printf("Milliseconds until next expiration: %d\n", remainingTime);
else
printf("Interval is not armed\n");- Source
set(intervalopt, nullable) → {boolean}nullable
Rearms the uloop interval timer with the specified interval.
This method rearms the interval timer with the specified interval value, allowing it to trigger repeatedly after the specified amount of time. If no interval value or null is provided, the interval is disarmed and keeps its callback, so that a later call can rearm it.
| Name | Type | Description |
|---|---|---|
interval | number | (optional, nullable) Optional. The interval value in milliseconds specifying when the interval triggers again. Without a value, the interval is disarmed. |
Returns true on success, null on error, such as a zero or negative interval.
// Rearm the uloop interval with a interval of 1000 milliseconds
const success = interval.set(1000);
if (success)
printf("Interval rearmed successfully\n");
else
printf("Error occurred while rearming interval: ${uloop.error()}\n");
// Disable the uloop interval
const success = interval.set();
if (success)
printf("Interval disabled successfully\n");
else
printf("Error occurred while disabling interval: ${uloop.error()}\n");- Source