ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/EV/EV.pm
Revision: 1.107
Committed: Mon Mar 16 11:12:53 2020 UTC (4 years, 2 months ago) by root
Branch: MAIN
CVS Tags: rel-6_57, HEAD
Changes since 1.106: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Coro::EV - do events the coro-way, with EV
4
5 =head1 SYNOPSIS
6
7 use Coro;
8 use Coro::EV;
9
10 EV::READ & Coro::EV::timed_io_once $fh, EV::READ, 60
11 or die "timeout\n";
12
13 EV::run;
14
15 =head1 DESCRIPTION
16
17 This module does two things: First, it offers some utility functions that
18 might be useful for threads (although L<Coro::AnyEvent> offers more and
19 more portable functions), and secondly, it integrates Coro into the EV
20 main loop:
21
22 Before the process blocks (in EV::run) to wait for events, this module
23 will schedule and run all ready (= runnable) threads of the same or
24 higher priority. After that, it will cede once to a threads of lower
25 priority, then continue in the event loop.
26
27 That means that threads with the same or higher priority as the threads
28 running the main loop will inhibit event processing, while threads of
29 lower priority will get the CPU, but cannot completeley inhibit event
30 processing. Note that for that to work you actually have to run the EV
31 event loop in some thread.
32
33 =head1 RUNNING WITH OR WITHOUT A MAINLOOP
34
35 In general, you should always run EV::run, either in your main program,
36 or in a separate coroutine. If you don't do that and all coroutines
37 start waiting for some events, this module will run the event loop once,
38 but this is very inefficient and will also not make it possible to run
39 background threads.
40
41 To run the EV event loop in a separate thread, you can simply do this:
42
43 async { EV::run };
44
45 =head1 FUNCTIONS
46
47 =over 4
48
49 =cut
50
51 package Coro::EV;
52
53 use common::sense;
54
55 use Carp;
56
57 use Coro;
58
59 use EV ();
60 use XSLoader;
61
62 BEGIN {
63 our $VERSION = 6.57;
64
65 local $^W = 0; # avoid redefine warning for Coro::ready;
66 XSLoader::load __PACKAGE__, $VERSION;
67 }
68
69 our $IDLE = new Coro sub {
70 while () {
71 &_loop_oneshot;
72 Coro::schedule if Coro::nready;
73 }
74 };
75 $IDLE->{desc} = "[EV idle thread]";
76
77 $Coro::idle = $IDLE;
78
79 =item $revents = Coro::EV::timed_io_once $fileno_or_fh, $events[, $timeout]
80
81 Blocks the coroutine until either the given event set has occurred on the
82 fd, or the timeout has been reached (if timeout is missing or C<undef>
83 then there will be no timeout). Returns the received flags.
84
85 Consider using C<Coro::AnyEvent::readable> and C<Coro::AnyEvent::writable>
86 instead, they work with any AnyEvent-supported event loop.
87
88 =item Coro::EV::timer_once $after
89
90 Blocks the coroutine for at least C<$after> seconds.
91
92 Consider using C<Coro::AnyEvent::sleep> instead, which works with any
93 AnyEvent-supported event loop.
94
95 =cut
96
97 1;
98
99 =back
100
101 =head1 AUTHOR/SUPPORT/CONTACT
102
103 Marc A. Lehmann <schmorp@schmorp.de>
104 http://software.schmorp.de/pkg/Coro.html
105
106 =cut
107