Mojo::Reactor::EV(3)
πΈ NAME πΈ
Mojo::Reactor::EV β low-level event reactor with libev support. Welcome to Mojo::Reactor::EV(3), from the User Contributed Perl Documentation corner of the universe, bestie. πβ¨
β¨ SYNOPSIS β¨
okay so hereβs the whole vibe in code, no cap:
use Mojo::Reactor::EV;
# Watch if handle becomes readable or writable
my $reactor = Mojo::Reactor::EV->new;
$reactor->io($first => sub ($reactor, $writable) {
say $writable ? 'First handle is writable' : 'First handle is readable';
});
# Change to watching only if handle becomes writable
$reactor->watch($first, 0, 1);
# Turn file descriptor into handle and watch if it becomes readable
my $second = IO::Handle->new_from_fd($fd, 'r');
$reactor->io($second => sub ($reactor, $writable) {
say $writable ? 'Second handle is writable' : 'Second handle is readable';
})->watch($second, 1, 0);
# Add a timer
$reactor->timer(15 => sub ($reactor) {
$reactor->remove($first);
$reactor->remove($second);
say 'Timeout!';
});
# Start reactor if necessary
$reactor->start unless $reactor->is_running;
π DESCRIPTION π
Mojo::Reactor::EV is a low-level event reactor based on EV (4.32+). Itβs literally giving low-level reactor energy, and itβs built on EV 4.32+. π
π EVENTS π
Mojo::Reactor::EV inherits all events from Mojo::Reactor::Poll. Every single one. Slay. β¨
π§ METHODS π§
Mojo::Reactor::EV inherits all methods from Mojo::Reactor::Poll and implements the following new ones. So yes, all the old faves plus these new icons. π
π« again π«
$reactor->again($id);
$reactor->again($id, 0.5);
Restarts the timer and optionally changes the invocation time.
π¨ vibe check: this method requires an active timer. Do not come for this method with no active timer, bestie.
π± new π±
my $reactor = Mojo::Reactor::EV->new;
Constructs a new Mojo::Reactor::EV object. Fresh reactor, fresh vibe. π¦
β one_tick β
$reactor->one_tick;
Runs the reactor until an event occurs or no events are being watched anymore.
# Don't block longer than 0.5 seconds
my $id = $reactor->timer(0.5 => sub {});
$reactor->one_tick;
$reactor->remove($id);
π recurring π
my $id = $reactor->recurring(0.25 => sub {...});
Creates a new recurring timer, invoking the callback repeatedly after a given amount of time in seconds. Itβs giving βagain and again and againβ energy. π
π start π
$reactor->start;
Starts watching for I/O and timer events. This will block until stop is called or no events are being watched anymore.
# Start reactor only if it is not running already
$reactor->start unless $reactor->is_running;
π stop π
$reactor->stop;
Stops watching for I/O and timer events. Thatβs the end of the watch era. π
β° timer β°
my $id = $reactor->timer(0.5 => sub {...});
Creates a new timer, invoking the callback after a given amount of time in seconds. Set it, let it cook, let the callback slay later. β³
π watch π
$reactor = $reactor->watch($handle, $readable, $writable);
Changes I/O events to watch the handle for, using true and false values.
π¨ vibe check: this method requires an active I/O watcher.
# Watch only for readable events
$reactor->watch($handle, 1, 0);
# Watch only for writable events
$reactor->watch($handle, 0, 1);
# Watch for readable and writable events
$reactor->watch($handle, 1, 1);
# Pause watching for events
$reactor->watch($handle, 0, 0);
π SEE ALSO π
MojoliciousMojolicious::Guides<https://mojolicious.org>
xoxo, your Unix bestie π
β this is Mojo::Reactor::EV(3), from perl v5.42.0, dated 2026-07-15. π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms