Purpose

The event loop is the central part of libuv’s functionality. It takes care of polling for i/o and scheduling callbacks to be run based on different sources of events.

run

uv.run( mode )

This function runs the event loop. It will act differently depending on the specified mode:

Modes

Mode Details
"default" Runs the event loop until there are no more active and referenced handles or requests.
"once" Poll for i/o once. Note that this function blocks if there are no pending callbacks.
"nowait" Poll for i/o once but don’t block if there are no pending callbacks.

Parameters

Name Details
mode The loop mode. See Modes above.

Examples

uv.run( "default" )

--OR

uv.run()

loop_alive

uv.loop_alive()

Returns non-zero if there are active handles or request in the loop.

Parameters

none

Examples

uv.loop_alive()

stop

uv.stop()

Stop the event loop, causing run to end as soon as possible. This will happen not sooner than the next loop iteration. If this function was called before blocking for i/o, the loop won’t block for i/o on this iteration.

Parameters

none

Examples

uv.stop()

loop_close

uv.loop_close()

Closes all internal loop resources. This function must only be called once the loop has finished its execution

Parameters

none

Examples

uv.loop_close()

backend_fd

uv.backend_fd()

Get backend file descriptor. Only kqueue, epoll and event ports are supported.

Parameters

none

Examples

local be_fd = uv.backend_fd()

backend_timeout

uv.backend_timeout()

Get the poll timeout. The return value is in milliseconds, or -1 for no timeout.

Parameters

none

Examples

local be_timeout = uv.backend_timeout()

now

uv.now()

Return the current timestamp in milliseconds. The timestamp is cached at the start of the event loop tick.

Parameters

none

Examples

local now = uv.now()

update_time

uv.update_time()

Update the event loop’s concept of “now”. Libuv caches the current time at the start of the event loop tick in order to reduce the number of time-related system calls.

Note

You won’t normally need to call this function unless you have callbacks that block the event loop for longer periods of time, where “longer” is somewhat subjective but probably on the order of a millisecond or more.

Parameters

none

Examples

uv.update_time()

walk

uv.walk( walk_callback )

Walk the list of handles: walk_callback will be executed with the given arg.

Parameters

Name Details
walk_callback The function to be run on each handle.

Examples

uv.walk( walk_callback )