public class TimerHandle extends Handle
See Timer handle
| Modifier and Type | Method and Description |
|---|---|
int |
again()
Stop the timer, and if it is repeating restart it using the repeat value as
the timeout.
|
void |
close()
Close the handle and free up any resources that may be held by it.
|
long |
getRepeat()
Get the timer repeat value.
|
static long |
now(LoopHandle loop)
Return the current timestamp in milliseconds.
|
void |
setCloseCallback(CloseCallback callback)
Attach a
CloseCallback. |
void |
setRepeat(long repeat)
Set the repeat interval value in milliseconds.
|
void |
setTimerFiredCallback(TimerCallback callback)
Attach a
TimerCallback. |
int |
start(long timeout,
long repeat)
Start the timer.
|
int |
stop()
Stop the timer, the callback will not be called anymore.
|
public void setTimerFiredCallback(TimerCallback callback)
TimerCallback.callback - A Callback, which will be invoked once per loop
iteration, right before the PrepareCallback
handles.public void setCloseCallback(CloseCallback callback)
CloseCallback.callback - A Callback, which will be invoked when check handle is
closed.IllegalStateException - if this method called more than once.public static long now(LoopHandle loop)
The timestamp increases monotonically from some arbitrary point in time. Don't make assumptions about the starting point, you will only get disappointed.
public int start(long timeout,
long repeat)
If timeout is zero, the callback fires on the next event loop iteration. If repeat is non-zero, the callback fires first after timeout milliseconds and then repeatedly after repeat milliseconds.
The timer will be scheduled to run on the given interval, regardless of the callback execution duration, and will follow normal timer semantics in the case of a time-slice overrun.
For example, if a 50ms repeating timer first runs for 17ms,
it will be scheduled to run again 33ms later. If other tasks consume
more than the @{code 33ms} following the first timer callback, then the
callback will run as soon as possible.
Note
If the repeat value is set from a timer callback it does not immediately take
effect. If the timer was non-repeating before, it will have been stopped. If
it was repeating, then the old repeat value will have been used to schedule
the next timeout.
timeout - timer's timeout value in milliseconds.repeat - timer's timer repeat value in milliseconds.public int again()
If the timer has never been started before it returns UV_EINVAL.
public long getRepeat()
public void setRepeat(long repeat)
The timer will be scheduled to run on the given interval, regardless of the callback execution duration, and will follow normal timer semantics in the case of a time-slice overrun.
For example, if a 50ms repeating timer first runs for 17ms, it will be scheduled to run again 33ms later. If other tasks consume more than the 33ms following the first timer callback, then the callback will run as soon as possible.
Note
If the repeat value is set from a timer callback it does not immediately take
effect. If the timer was non-repeating before, it will have been stopped. If
it was repeating, then the old repeat value will have been used to schedule
the next timeout.
repeat - timer's repeat value in milliseconds.public int stop()
0 on success, or an error code < 0 on failure.public void close()
CloseCallback callback will be invoked right before the close.
#setCloseCallback(CloseCallback)}Copyright © 2021 WebFolder. All rights reserved.