EV::Loop#

📦 max

An event loop of your own, beside the default one: EV::Loop->new makes one, and EV::default_loop returns the default loop as an EV::Loop too.

An EV::Loop has, as methods, the EV:: functions that work on a loop: $loop->run, $loop->now, $loop->timer(...), $loop->io(...) and so on, each doing for this loop what the EV:: function does for the default loop - see those for the details. A loop lives as long as the object, or a watcher on it, does.

A loop of your own may use another backend than the default loop (EV::BACKEND_* flags), or serve part of a program separately. Child process watchers work only on the default loop, and a signal can be watched by one loop at a time. After fork, the child must call $loop->loop_fork before using such a loop, unless it was made with EV::FLAG_FORKCHECK.

Synopsis#

my $loop = EV::Loop->new;
my $t = $loop->timer(1, 0, sub { print "tick\n"; $loop->break });
$loop->run;

Functions#

Loops#

new#

Make a new event loop: EV::Loop->new, or EV::Loop->new($flags) with EV::BACKEND_* bits to choose its backends and EV::FLAG_* bits (EV::FLAG_FORKCHECK to recover from fork by itself, EV::FLAG_NOENV to ignore LIBEV_FLAGS). Undef when no requested backend works.

loop_fork#

Prepare the loop for use in a child process after fork: call it in the child before running the loop again. Loops made with EV::FLAG_FORKCHECK, and the default loop, do it by themselves.

Running the loop#

iteration#

How many times this loop has waited for events, as EV::iteration; loop_count is its old name.

Also available as EV::Loop::loop_count.

depth#

How many run calls of this loop are in progress, as EV::depth; loop_depth is its old name.

Also available as EV::Loop::loop_depth.

loop#

Run this loop: $loop->run, $loop->run(EV::RUN_ONCE), $loop->run(EV::RUN_NOWAIT), as EV::run runs the default loop. True when it returned with work left. loop is its old name.

Also available as EV::Loop::run.

break#

Make this loop’s run return, as EV::break: $loop->break, $loop->break(EV::BREAK_ALL). unloop is its old name.

Also available as EV::Loop::unloop.

Watchers#

io#

An I/O watcher on this loop: $loop->io($fh, EV::READ, sub { ... }), as EV::io; io_ns makes it stopped.

Also available as EV::Loop::io_ns.

timer#

A timer on this loop: $loop->timer($after, $repeat, sub { ... }), as EV::timer; timer_ns makes it stopped.

Also available as EV::Loop::timer_ns.

periodic#

A wall-clock timer on this loop: $loop->periodic($at, $interval, $reschedule_cb, sub { ... }), as EV::periodic; periodic_ns makes it stopped.

Also available as EV::Loop::periodic_ns.

signal#

A signal watcher on this loop: $loop->signal('HUP', sub { ... }), as EV::signal; signal_ns makes it stopped. A signal can be watched by one loop at a time.

Also available as EV::Loop::signal_ns.

idle#

An idle watcher on this loop: $loop->idle(sub { ... }), as EV::idle; idle_ns makes it stopped.

Also available as EV::Loop::idle_ns.

prepare#

A prepare watcher on this loop, as EV::prepare; prepare_ns makes it stopped.

Also available as EV::Loop::prepare_ns.

check#

A check watcher on this loop, as EV::check; check_ns makes it stopped.

Also available as EV::Loop::check_ns.

fork#

A fork watcher on this loop, as EV::fork; fork_ns makes it stopped.

Also available as EV::Loop::fork_ns.

child#

A child process watcher: $loop->child($pid, $trace, sub { ... }), as EV::child; child_ns makes it stopped. Only the default loop can watch children: call it on EV::default_loop.

Also available as EV::Loop::child_ns.

stat#

A file status watcher on this loop: $loop->stat($path, $interval, sub { ... }), as EV::stat; stat_ns makes it stopped.

Also available as EV::Loop::stat_ns.

embed#

Embed another loop in this one: $loop->embed($other), as EV::embed; embed_ns makes the watcher stopped.

Also available as EV::Loop::embed_ns.

async#

An async watcher on this loop, as EV::async; async_ns makes it stopped.

Also available as EV::Loop::async_ns.

once#

Wait once on this loop for a handle, a timeout, or the first of the two: $loop->once($fh, EV::READ, 10, sub { my ($revents) = @_; ... }), as EV::once.

Time#

now#

The time this loop’s current iteration began, as EV::now.

now_update#

Set this loop’s time to the time now, as EV::now_update.

suspend#

Pause this loop’s clock, as EV::suspend; only resume may follow.

resume#

Restart this loop’s clock after suspend, as EV::resume.

Events#

feed_fd_event#

Act as if a file descriptor had become ready, for this loop’s watchers, as EV::feed_fd_event.

pending_count#

How many of this loop’s watchers are pending, as EV::pending_count.

invoke_pending#

Call the callbacks of this loop’s pending watchers now, as EV::invoke_pending.

Tuning#

set_io_collect_interval#

Make this loop wait at least this long between polls for I/O, as EV::set_io_collect_interval.

set_timeout_collect_interval#

Let this loop’s timers that expire close together fire in one wakeup, as EV::set_timeout_collect_interval.

backend#

The backend this loop waits with, one EV::BACKEND_* bit.

loop_verify#

Check this loop’s internal data, aborting if it is corrupt, as EV::verify; loop_verify is its old name.

Also available as EV::Loop::verify.