ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV/AnyEvent.pm
Revision: 1.10
Committed: Fri Nov 9 19:33:52 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +0 -0 lines
State: FILE REMOVED
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     EV::AnyEvent - anyevent adaptor for EV
4    
5     =head1 SYNOPSIS
6    
7 root 1.3 use AnyEvent;
8     use EV;
9    
10     # this module gets loaded automatically as required
11 root 1.1
12     =head1 DESCRIPTION
13    
14 root 1.3 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 root 1.8 before creating the first AnyEvent watcher.
17 root 1.1
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 root 1.2 fileno $arg{fh},
39 root 1.6 ($arg{poll} =~ /r/ ? EV::READ : 0) | ($arg{poll} =~ /w/ ? EV::WRITE : 0),
40 root 1.1 sub {
41     $cb->( ($_[1] & EV::READ ? "r" : "") . ($_[1] & EV::WRITE ? "w" : "") );
42     }
43     }
44    
45 root 1.5 sub signal {
46     my ($class, %arg) = @_;
47    
48     EV::signal $arg{signal}, $arg{cb}
49     }
50 root 1.4
51 root 1.7 sub child {
52     my ($class, %arg) = @_;
53    
54 root 1.9 my $cb = $arg{cb};
55    
56     EV::child $arg{pid}, sub {
57     $cb->($_[0]->rpid, $_[0]->rstatus);
58     }
59 root 1.7 }
60    
61 root 1.1 sub condvar {
62     bless \my $flag, "EV::AnyEvent"
63     }
64    
65     sub broadcast {
66     ${$_[0]}++;
67     }
68    
69     sub wait {
70 root 1.6 EV::loop EV::LOOP_ONESHOT
71 root 1.1 while !${$_[0]};
72     }
73    
74     sub one_event {
75 root 1.6 EV::loop EV::LOOP_ONESHOT;
76 root 1.1 }
77    
78     1;
79    
80     =head1 SEE ALSO
81    
82     L<AnyEvent>.
83    
84     =head1 AUTHOR
85    
86     Marc Lehmann <schmorp@schmorp.de>
87     http://home.schmorp.de/
88    
89     =cut
90