EV(3pm)
π Coro::EV β do events the coro-way, with EV π
ok so bestie, this is a User Contributed Perl Documentation page for EV(3pm) and it's genuinely so good, sit down, we're doing events the coro-way. β¨
πΈ NAME πΈ
Coro::EV β do events the coro-way, with EV π¦
β¨ SYNOPSIS β¨
use Coro;
use Coro::EV;
EV::READ & Coro::EV::timed_io_once $fh, EV::READ, 60
or die "timeout\n";
EV::run;
like. that's it. that's the whole vibe. π
π DESCRIPTION π
okay so this module is doing two things at once, main character energy fr:
- it hands you some utility functions that might be useful for threads β tho ngl,
Coro::AnyEventoffers more and more portable functions, so keep that in mind π - it integrates
Corointo theEVmain loop π
Here's the tea on how the integration works: before the process blocks (in EV::run) to wait for events, this module will schedule and run all ready (= runnable) threads of the same or higher priority. After that, it will cede once to a thread of lower priority, then continue in the event loop.
So what does that actually mean for you? Threads with the same or higher priority as the threads running the main loop will inhibit event processing π€ β meanwhile threads of lower priority will get the CPU, but they cannot completeley inhibit event processing. (yes, that typo is in the original, we respect the lore π)
β οΈ Note that for that to work you actually have to run the EV event loop in some thread. no mainloop, no magic, bestie.
π RUNNING WITH OR WITHOUT A MAINLOOP π
In general? You should always run EV::run β either in your main program, or in a separate coroutine. Periodt.
If you don't do that and all coroutines start waiting for some events, this module will run the event loop once, but lowkey this is very inefficient and it will also not make it possible to run background threads. it's giving "technically works, spiritually a mess" π
To run the EV event loop in a separate thread, you can simply do this:
async { EV::run };
iconic. effortless. slay. π§
π FUNCTIONS π
$revents = Coro::EV::timed_io_once $fileno_or_fh, $events[, $timeout]β blocks the coroutine until either the given event set has occurred on the fd, or the timeout has been reached (if timeout is missing orundefthen there will be no timeout, so like... forever girl, be careful π«Ά). Returns the received flags.
Consider using Coro::AnyEvent::readable and Coro::AnyEvent::writable instead β they work with any AnyEvent-supported event loop. π
Coro::EV::timer_once $afterβ blocks the coroutine for at least$afterseconds. β³
Consider using Coro::AnyEvent::sleep instead, which works with any AnyEvent-supported event loop. πΈ
π AUTHOR/SUPPORT/CONTACT π
Marc A. Lehmann <schmorp@schmorp.de>
http://software.schmorp.de/pkg/Coro.html
and that's the whole page bestie!! π this doc is from perl v5.40.1, dated 2025-03-21, so yeah β that's the era we're living in. go run your event loop in a coroutine and text me how it goes. mwah π«Άβ¨π
π¦ where this page comes from
- debian trixie: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms