1 |
root |
1.1 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
Coro::EV - do events the coro-way |
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS |
6 |
|
|
|
7 |
|
|
use Coro; |
8 |
|
|
use Coro::EV; |
9 |
|
|
|
10 |
|
|
loop; |
11 |
|
|
|
12 |
|
|
=head1 DESCRIPTION |
13 |
|
|
|
14 |
|
|
=head1 FUNCTIONS |
15 |
|
|
|
16 |
|
|
=over 4 |
17 |
|
|
|
18 |
|
|
=cut |
19 |
|
|
|
20 |
|
|
package Coro::EV; |
21 |
|
|
|
22 |
|
|
no warnings; |
23 |
|
|
|
24 |
|
|
use Carp; |
25 |
|
|
no warnings; |
26 |
|
|
|
27 |
|
|
use Coro; |
28 |
|
|
use Coro::Timer; |
29 |
|
|
|
30 |
|
|
use EV (); |
31 |
|
|
use XSLoader; |
32 |
|
|
|
33 |
|
|
BEGIN { |
34 |
|
|
our $VERSION = '2.1'; |
35 |
|
|
|
36 |
|
|
local $^W = 0; # avoid redefine warning for Coro::ready; |
37 |
|
|
XSLoader::load __PACKAGE__, $VERSION; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
=cut |
41 |
|
|
|
42 |
|
|
=item |
43 |
|
|
|
44 |
|
|
=item Coro::EV::loop |
45 |
|
|
|
46 |
|
|
You have to call this function instead of EV::loop, EV::dispatch and |
47 |
|
|
similar functions. EV is not generic enough to let Coro hook into yet, so |
48 |
|
|
you have to use those replacement functions. |
49 |
|
|
|
50 |
|
|
=item $revents = Coro::EV::timed_io_once $fd, $events, $timeout |
51 |
|
|
|
52 |
|
|
Blocks the coroutine until either the given event set has occured on the |
53 |
|
|
fd, or the timeout has been reached (if timeout is zero, there is no |
54 |
|
|
timeout). Returns the received flags. |
55 |
|
|
|
56 |
|
|
=item Coro::EV::timer_once $after |
57 |
|
|
|
58 |
|
|
Blocks the coroutine for at least C<$after> seconds. |
59 |
|
|
|
60 |
|
|
=cut |
61 |
|
|
|
62 |
|
|
# relatively inefficient |
63 |
|
|
our $ev_idle = new Coro sub { |
64 |
|
|
while () { |
65 |
|
|
EV::loop EV::LOOP_ONESHOT; |
66 |
|
|
&Coro::schedule; |
67 |
|
|
} |
68 |
|
|
}; |
69 |
|
|
$ev->{desc} = "[EV idle process]"; |
70 |
|
|
|
71 |
|
|
$Coro::idle = sub { $ev_idle->ready }; |
72 |
|
|
|
73 |
|
|
sub timed_io_once($$;$) { |
74 |
|
|
&_timed_io_once; |
75 |
|
|
do { &Coro::schedule } while !$#_; |
76 |
|
|
pop |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
sub timer_once($) { |
80 |
|
|
&_timer_once; |
81 |
|
|
do { &Coro::schedule } while !$#_; |
82 |
|
|
pop |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
#sub timer_abs_once($$) { |
86 |
|
|
# &_timer_abs_once; |
87 |
|
|
# do { &Coro::schedule } while !$#_; |
88 |
|
|
# pop |
89 |
|
|
#} |
90 |
|
|
|
91 |
|
|
1; |
92 |
|
|
|
93 |
|
|
=back |
94 |
|
|
|
95 |
|
|
=head1 AUTHOR |
96 |
|
|
|
97 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
98 |
|
|
http://home.schmorp.de/ |
99 |
|
|
|
100 |
|
|
=cut |
101 |
|
|
|