1 |
=head1 NAME |
2 |
|
3 |
EV::AnyEvent - anyevent adaptor for EV |
4 |
|
5 |
=head1 SYNOPSIS |
6 |
|
7 |
# this module gets loaded automatically when required |
8 |
|
9 |
=head1 DESCRIPTION |
10 |
|
11 |
This module provides transparent support for AnyEvent. |
12 |
|
13 |
=cut |
14 |
|
15 |
package EV::AnyEvent; |
16 |
|
17 |
use strict; |
18 |
|
19 |
use EV; |
20 |
|
21 |
sub timer { |
22 |
my ($class, %arg) = @_; |
23 |
|
24 |
EV::timer $arg{after}, 0, $arg{cb} |
25 |
} |
26 |
|
27 |
sub io { |
28 |
my ($class, %arg) = @_; |
29 |
|
30 |
my $cb = $arg{cb}; |
31 |
|
32 |
EV::io |
33 |
$arg{fh}, |
34 |
($arg{poll} =~ /r/ ? EV::READ : 0) | ($arg{poll} =~ /w/ ? EV::WRITE : 0) | EV::PERSIST, |
35 |
sub { |
36 |
$cb->( ($_[1] & EV::READ ? "r" : "") . ($_[1] & EV::WRITE ? "w" : "") ); |
37 |
} |
38 |
} |
39 |
|
40 |
sub condvar { |
41 |
bless \my $flag, "EV::AnyEvent" |
42 |
} |
43 |
|
44 |
sub broadcast { |
45 |
${$_[0]}++; |
46 |
} |
47 |
|
48 |
sub wait { |
49 |
EV::loop EV::LOOP_ONCE |
50 |
while !${$_[0]}; |
51 |
} |
52 |
|
53 |
sub one_event { |
54 |
EV::loop EV::LOOP_ONCE; |
55 |
} |
56 |
|
57 |
1; |
58 |
|
59 |
=head1 SEE ALSO |
60 |
|
61 |
L<AnyEvent>. |
62 |
|
63 |
=head1 AUTHOR |
64 |
|
65 |
Marc Lehmann <schmorp@schmorp.de> |
66 |
http://home.schmorp.de/ |
67 |
|
68 |
=cut |
69 |
|