line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2014-2015 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Event::Distributor::Query; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
36202
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
71
|
|
9
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
80
|
|
10
|
3
|
|
|
3
|
|
15
|
use base qw( Event::Distributor::_Event ); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
693
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
41
|
use Future; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
530
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
C - an event that collects a result |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This subclass of L invokes each of its subscribers |
23
|
|
|
|
|
|
|
in turn, yielding either the (first) successful result, or a failure if they |
24
|
|
|
|
|
|
|
all fail. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub fire |
29
|
|
|
|
|
|
|
{ |
30
|
2
|
|
|
2
|
1
|
8
|
my $self = shift; |
31
|
2
|
|
|
|
|
4
|
my ( $dist, @args ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
4
|
my $await = $self->{await}; |
34
|
2
|
|
|
|
|
2
|
my @f; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
10
|
foreach my $sub ( $self->subscribers ) { |
37
|
2
|
|
|
|
|
6
|
my $f = $sub->( $dist, @args ); |
38
|
2
|
|
|
|
|
43
|
push @f, $f; |
39
|
|
|
|
|
|
|
|
40
|
2
|
50
|
33
|
|
|
7
|
last if $f->is_ready and !$f->failure; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return Future->needs_any( @f )->then( sub { |
44
|
2
|
|
|
2
|
|
307
|
my @results = @_; |
45
|
|
|
|
|
|
|
# TODO: conversions? |
46
|
2
|
|
|
|
|
6
|
Future->done( @results ); |
47
|
2
|
|
|
|
|
37
|
}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 AUTHOR |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Paul Evans |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
0x55AA |