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 $revents = Coro::EV::timed_io_once $fd, $events, $timeout |
45 |
|
46 |
Blocks the coroutine until either the given event set has occured on the |
47 |
fd, or the timeout has been reached (if timeout is zero, there is no |
48 |
timeout). Returns the received flags. |
49 |
|
50 |
=item Coro::EV::timer_once $after |
51 |
|
52 |
Blocks the coroutine for at least C<$after> seconds. |
53 |
|
54 |
=cut |
55 |
|
56 |
# relatively inefficient |
57 |
our $ev_idle = new Coro sub { |
58 |
while () { |
59 |
EV::loop EV::LOOP_ONESHOT; |
60 |
&Coro::schedule; |
61 |
} |
62 |
}; |
63 |
$ev->{desc} = "[EV idle process]"; |
64 |
|
65 |
$Coro::idle = sub { $ev_idle->ready }; |
66 |
|
67 |
sub timed_io_once($$;$) { |
68 |
&_timed_io_once; |
69 |
do { &Coro::schedule } while !$#_; |
70 |
pop |
71 |
} |
72 |
|
73 |
sub timer_once($) { |
74 |
&_timer_once; |
75 |
do { &Coro::schedule } while !$#_; |
76 |
pop |
77 |
} |
78 |
|
79 |
#sub timer_abs_once($$) { |
80 |
# &_timer_abs_once; |
81 |
# do { &Coro::schedule } while !$#_; |
82 |
# pop |
83 |
#} |
84 |
|
85 |
1; |
86 |
|
87 |
=back |
88 |
|
89 |
=head1 AUTHOR |
90 |
|
91 |
Marc Lehmann <schmorp@schmorp.de> |
92 |
http://home.schmorp.de/ |
93 |
|
94 |
=cut |
95 |
|