|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. _timer:
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
:c:type:`uv_timer_t` --- Timer handle
|
|
Packit Service |
7c31a4 |
=====================================
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Timer handles are used to schedule callbacks to be called in the future.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Data types
|
|
Packit Service |
7c31a4 |
----------
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:type:: uv_timer_t
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Timer handle type.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:type:: void (*uv_timer_cb)(uv_timer_t* handle)
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Type definition for callback passed to :c:func:`uv_timer_start`.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Public members
|
|
Packit Service |
7c31a4 |
^^^^^^^^^^^^^^
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
N/A
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. seealso:: The :c:type:`uv_handle_t` members also apply.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
API
|
|
Packit Service |
7c31a4 |
---
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:function:: int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle)
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Initialize the handle.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:function:: int uv_timer_start(uv_timer_t* handle, uv_timer_cb cb, uint64_t timeout, uint64_t repeat)
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Start the timer. `timeout` and `repeat` are in milliseconds.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
If `timeout` is zero, the callback fires on the next event loop iteration.
|
|
Packit Service |
7c31a4 |
If `repeat` is non-zero, the callback fires first after `timeout`
|
|
Packit Service |
7c31a4 |
milliseconds and then repeatedly after `repeat` milliseconds.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. note::
|
|
Packit Service |
7c31a4 |
Does not update the event loop's concept of "now". See :c:func:`uv_update_time` for more information.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
If the timer is already active, it is simply updated.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:function:: int uv_timer_stop(uv_timer_t* handle)
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Stop the timer, the callback will not be called anymore.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:function:: int uv_timer_again(uv_timer_t* handle)
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Stop the timer, and if it is repeating restart it using the repeat value
|
|
Packit Service |
7c31a4 |
as the timeout. If the timer has never been started before it returns
|
|
Packit Service |
7c31a4 |
UV_EINVAL.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:function:: void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat)
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Set the repeat interval value in milliseconds. The timer will be scheduled
|
|
Packit Service |
7c31a4 |
to run on the given interval, regardless of the callback execution
|
|
Packit Service |
7c31a4 |
duration, and will follow normal timer semantics in the case of a
|
|
Packit Service |
7c31a4 |
time-slice overrun.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
For example, if a 50ms repeating timer first runs for 17ms, it will be
|
|
Packit Service |
7c31a4 |
scheduled to run again 33ms later. If other tasks consume more than the
|
|
Packit Service |
7c31a4 |
33ms following the first timer callback, then the callback will run as soon
|
|
Packit Service |
7c31a4 |
as possible.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. note::
|
|
Packit Service |
7c31a4 |
If the repeat value is set from a timer callback it does not immediately take effect.
|
|
Packit Service |
7c31a4 |
If the timer was non-repeating before, it will have been stopped. If it was repeating,
|
|
Packit Service |
7c31a4 |
then the old repeat value will have been used to schedule the next timeout.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
.. c:function:: uint64_t uv_timer_get_repeat(const uv_timer_t* handle)
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
7c31a4 |
Get the timer repeat value.
|
|
Packit Service |
7c31a4 |
|
|
Packit Service |
e2ebee |
.. c:function:: uint64_t uv_timer_get_due_in(const uv_timer_t* handle)
|
|
Packit Service |
e2ebee |
|
|
Packit Service |
e2ebee |
Get the timer due value or 0 if it has expired. The time is relative to
|
|
Packit Service |
e2ebee |
:c:func:`uv_now()`.
|
|
Packit Service |
e2ebee |
|
|
Packit Service |
e2ebee |
.. versionadded:: 1.40.0
|
|
Packit Service |
e2ebee |
|
|
Packit Service |
7c31a4 |
.. seealso:: The :c:type:`uv_handle_t` API functions also apply.
|