Module lzmq.loop
ZMQ event loop.
Functions
-
new ([pre_alloc[, ctx]])
-
Create new loop object.
Parameters:
- pre_alloc
number
pre-size the poller for the number of sockets it will handle.
The size can grow dynamically as-needed.
- ctx
lzmq.context
ZMQ context.
Returns:
loop
Class loop
-
loop:add_socket (socket[, events=zmq.POLLIN], callback)
-
Add a ZMQ Socket or fd to the poller.
You can add one socket multiple times.
Parameters:
- socket
(lzmq.socket or number)
ZMQ socket or fd
- events
number
zmq poll events bitmask
(default zmq.POLLIN)
- callback
callable
called when event is raised
Returns:
lzmq.socket
socket
Usage:
loop:add_socket(sock, function(sock) print(sock, " is readable.") end)
loop:add_socket(sock, zmq.POLLOUT, function(sock) print(sock, " is writable.") end)
loop:add_socket(sock, zmq.POLLIN+zmq.POLLOUT, function(sock, revents)
print(sock, " has events:", revents)
end)
-
loop:add_time (time, callback)
-
Add a time event.
Parameters:
- time
number
UTC absolute time
- callback
callable
called when event is raised
Returns:
lzmq.time_event
-
loop:add_interval (interval, callback)
-
Add a time event.
Parameters:
- interval
number
milliseconds to event scince now
- callback
callable
called when event is raised
Returns:
lzmq.time_event
-
loop:add_once (interval, callback)
-
Add a time event.
Parameters:
- interval
number
milliseconds to event scince now
- callback
callable
called when event is raised
Returns:
lzmq.time_event
-
loop:remove_socket (socket)
-
Remove a socket/fd from the poller.
Note. You can remove only `last` socket.
Parameters:
-
loop:start ()
-
Start an event loop waiting for and dispatching events.
-
loop:sleep_ex (interval)
-
Whait some interval and dispatch events
Parameters:
- interval
number
milliseconds to event scince now
-
loop:flush (interval)
-
Proceed IO events.
Parameters:
- interval
number
maximum interval in milliseconds to proceed events
-
loop:context ()
-
Return internal ZMQ context
Returns:
lzmq.context
-
loop:interrupt ()
-
Interrupt event loop
-
loop:stop ()
-
Interrupt event loop
-
loop:destroy ([no_close=false])
-
Destroy loop object.
loop object can use only `close` method to close sockets object.
Parameters:
- no_close
boolean
by default close all sockets when destroy loop.
(default false)
Returns:
loop
Class time_event
Usage:
loop:add_interval(0,function(ev)
if work_done then return ev:reset()
end
ev:set_interval(1000)
end)
-
time_event:set_time (time)
-
Set absolute time.
Parameters:
- time
number
UTC absolute time
-
time_event:set_interval (milliseconds)
-
Set interval.
Parameters:
-
time_event:set_interval_once (milliseconds)
-
Set interval.
Parameters:
-
time_event:reset ()
-
Reset time event.
-
time_event:restart ()
-
Restart event.
Usage:
local watch_dog_ev = loop:add_interval(TIMEOUT, watch_dog_fn)
watch_dog_ev:restart()