ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV/AnyEvent.pm
Revision: 1.3
Committed: Fri Oct 26 19:25:01 2007 UTC (16 years, 7 months ago) by root
Branch: MAIN
CVS Tags: rel-0_02
Changes since 1.2: +7 -2 lines
Log Message:
*** empty log message ***

File Contents

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