.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "EV 3pm" .TH EV 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Coro::EV \- do events the coro\-way, with EV .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use Coro; \& use Coro::EV; \& \& EV::READ & Coro::EV::timed_io_once $fh, EV::READ, 60 \& or die "timeout\en"; \& \& EV::run; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module does two things: First, it offers some utility functions that might be useful for threads (although Coro::AnyEvent offers more and more portable functions), and secondly, it integrates Coro into the EV main loop: .PP 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 threads of lower priority, then continue in the event loop. .PP That means that threads with the same or higher priority as the threads running the main loop will inhibit event processing, while threads of lower priority will get the CPU, but cannot completeley inhibit event processing. Note that for that to work you actually have to run the EV event loop in some thread. .SH "RUNNING WITH OR WITHOUT A MAINLOOP" .IX Header "RUNNING WITH OR WITHOUT A MAINLOOP" In general, you should always run EV::run, either in your main program, or in a separate coroutine. If you don't do that and all coroutines start waiting for some events, this module will run the event loop once, but this is very inefficient and will also not make it possible to run background threads. .PP To run the EV event loop in a separate thread, you can simply do this: .PP .Vb 1 \& async { EV::run }; .Ve .SH FUNCTIONS .IX Header "FUNCTIONS" .ie n .IP "$revents = Coro::EV::timed_io_once $fileno_or_fh, $events[, $timeout]" 4 .el .IP "\f(CW$revents\fR = Coro::EV::timed_io_once \f(CW$fileno_or_fh\fR, \f(CW$events\fR[, \f(CW$timeout\fR]" 4 .IX Item "$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 or \f(CW\*(C`undef\*(C'\fR then there will be no timeout). Returns the received flags. .Sp Consider using \f(CW\*(C`Coro::AnyEvent::readable\*(C'\fR and \f(CW\*(C`Coro::AnyEvent::writable\*(C'\fR instead, they work with any AnyEvent-supported event loop. .ie n .IP "Coro::EV::timer_once $after" 4 .el .IP "Coro::EV::timer_once \f(CW$after\fR" 4 .IX Item "Coro::EV::timer_once $after" Blocks the coroutine for at least \f(CW$after\fR seconds. .Sp Consider using \f(CW\*(C`Coro::AnyEvent::sleep\*(C'\fR instead, which works with any AnyEvent-supported event loop. .SH AUTHOR/SUPPORT/CONTACT .IX Header "AUTHOR/SUPPORT/CONTACT" .Vb 2 \& Marc A. Lehmann \& http://software.schmorp.de/pkg/Coro.html .Ve