ZeroMQ::Poller(3) Convenient socket polling object


use ZeroMQ qw/:all/;
my $cxt = ZeroMQ::Context->new()
my $sock = ZeroMQ::Socket->new($cxt, ZMQ_REP);
my $poller = ZeroMQ::Poller->new(
name => 'amazing',
socket => $sock,
events => ZMQ_POLLIN,
callback => sub { do_something_amazing },
do_another_amazing_thing() if $poller->has_event(0);
do_a_third_amazing_thing() if $poller->has_event('amazing');


A "ZeroMQ::Poller" watches zero or more sockets for events and signals that these have occurred in several ways. Given a list of sockets and events to watch for, it can directly invoke a callback or simply raise a flag.



Creates a new "ZeroMQ::Poller"

The constructor accepts a list of hash references (``poll items''), each of which specifies a socket or file descriptor to watch and what to watch it for. In addition, each poll item may specify a callback to invoke or a name by which it may be queried. The accepted keys are:

Contains the "ZeroMQ::Socket" item to poll.
Contains the file descriptor to poll. One of "socket" or "fd" is required; "socket" has precedence.
Some combination of "ZMQ_POLLIN", "ZMQ_POLLOUT", and "ZMQ_POLLERR"; the events to trap.
A coderef taking no arguments and emitting no return value, invoked when the specified events occur on the socket or file descriptor. Optional.
A string, naming the poll item for later use with "has_event".


Blocks until there is activity or the given timeout is reached. If no timeout or a negative timeout is specified, blocks indefinitely. If a timeout is given, it is interpreted as microseconds.



Returns true if the poll item at the given index or with the given name reported activity during the last call to "poll".