File Coverage

blib/lib/AnyEvent/Collect.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             # ABSTRACT: Block till one or more events fire
2             package AnyEvent::Collect;
3             {
4             $AnyEvent::Collect::VERSION = '0.1.0';
5             }
6 1     1   32992 use strict;
  1         2  
  1         43  
7 1     1   7 use warnings;
  1         2  
  1         31  
8 1     1   6 use AnyEvent;
  1         6  
  1         17  
9 1     1   1688 use Event::Wrappable;
  0            
  0            
10             use Sub::Exporter -setup => {
11             exports => [qw( collect collect_all collect_any event )],
12             groups => { default => [qw( collect collect_all collect_any event )] },
13             };
14              
15             use constant COLLECT_TYPE => 0;
16             use constant COLLECT_CV => 1;
17              
18             my @cvs;
19              
20              
21              
22             sub collect_all(&) {
23             my( $todo ) = @_;
24             my $cv = AE::cv;
25             Event::Wrappable->wrap_events( $todo, sub {
26             my( $listener ) = @_;
27             $cv->begin;
28             my $ended = 0;
29             return sub { $listener->(@_); $cv->end unless $ended++ };
30             } );
31             $cv->recv;
32             }
33             *collect = *collect_all;
34              
35             sub collect_any(&) {
36             my( $todo ) = @_;
37             my $cv = AE::cv;
38             Event::Wrappable->wrap_events( $todo, sub {
39             my( $listener ) = @_;
40             return sub { $listener->(@_); $cv->send };
41             } );
42             $cv->recv;
43             }
44              
45             1;
46              
47             __END__