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 🌈


xoxo, your Unix bestie πŸ’… β€” this is Mojo::Reactor::EV(3), from perl v5.42.0, dated 2026-07-15. 🫢✨

πŸ“¦ where this page comes from