loop#

Run the event loop: wait for events and call the watchers’ callbacks.

Also available as EV::run.

Synopsis#

EV::run;                  # until EV::break, or no active watcher is left
EV::run EV::RUN_ONCE;     # wait for events once, handle them, return
EV::run EV::RUN_NOWAIT;   # handle what is ready now, without waiting

What you get back#

True when it returned with work left - after EV::break, or with EV::RUN_ONCE or EV::RUN_NOWAIT - and false when no active watcher that keeps the loop alive was left.

Examples#

Wait for input, at most five seconds:

my $in  = EV::io *STDIN, EV::READ, sub { print "input\n"; EV::break };
my $max = EV::timer 5, 0, sub { print "timeout\n"; EV::break };
EV::run;

Edge cases#

  • A watcher whose keepalive is off does not keep EV::run from returning.

  • A callback may call EV::run again; the inner call returns first.

  • EV::loop is the old name, from EV 3.

Differences from upstream#

Fully compatible with upstream. Covered by t/81-xs-native/EV/130-upstream-03_keepalive.t.

See also#

  • EV::break - makes EV::run return

  • EV::once - waits for one event without a watcher object