integer for the
handle's type (`uv_handle_type`).
Returns: `string, integer`
==============================================================================
REFERENCE COUNTING *luv-reference-counting*
The libuv event loop (if run in the default mode) will run until there are no
active and referenced handles left. The user can force the loop to exit early
by unreferencing handles which are active, for example by calling |uv.unref()|
after calling |uv.timer_start()|.
A handle can be referenced or unreferenced, the refcounting scheme doesn't use
a counter, so both operations are idempotent.
All handles are referenced when active by default, see |uv.is_active()| for a
more detailed explanation on what being active involves.
==============================================================================
`uv_timer_t` — Timer handle *luv-timer-handle* *uv_timer_t*
> |uv_handle_t| functions also apply.
Timer handles are used to schedule callbacks to be called in the future.
uv.new_timer() *uv.new_timer()*
Creates and initializes a new |uv_timer_t|. Returns the Lua
userdata wrapping it.
Returns: `uv_timer_t userdata` or `fail`
>lua
-- Creating a simple setTimeout wrapper
local function setTimeout(timeout, callback)
local timer = uv.new_timer()
timer:start(timeout, 0, function ()
timer:stop()
timer:close()
callback()
end)
return timer
end
-- Creating a simple setInterval wrapper
local function setInterval(interval, callback)
local timer = uv.new_timer()
timer:start(interval, interval, function ()
callback()
end)
return timer
end
-- And clearInterval
local function clearInterval(timer)
timer:stop()
timer:close()
end
<
uv.timer_start({timer}, {timeout}, {repeat}, {callback}) *uv.timer_start()*
> method form `timer:start(timeout, repeat, callback)`
Parameters:
- `timer`: `uv_timer_t userdata`
- `timeout`: `integer`
- `repeat`: `integer`
- `callback`: `callable`
Start the timer. `timeout` and `repeat` are in milliseconds.
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.
Returns: `0` or `fail`
uv.timer_stop({timer}) *uv.timer_stop()*
> method form `timer:stop()`
Parameters:
- `timer`: `uv_timer_t userdata`
Stop the timer, the callback will not be called anymore.
Returns: `0` or `fail`
uv.timer_again({timer}) *uv.timer_again()*
> method form `timer:again()`
Parameters:
- `timer`: `uv_timer_t userdata`
Stop the timer, and if it is repeating restart it using the
repeat value as the timeout. If the timer has never been
started before it raises `EINVAL`.
Returns: `0` or `fail`
uv.timer_set_repeat({timer}, {repeat}) *uv.timer_set_repeat()*
> method form `timer:set_repeat(repeat)`