| 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, 2009 -- leonerd@leonerd.org.uk |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package CPS::Governor::IOAsync; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
174946
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
104
|
|
|
9
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
98
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
27
|
use Carp; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
238
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
16
|
use base qw( CPS::Governor::Deferred ); |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
2593
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
C - use L with L |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use CPS qw( gkforeach ); |
|
24
|
|
|
|
|
|
|
use CPS::Governor::IOAsync; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use IO::Async::Loop; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $gov = CPS::Governor::IOAsync->new( loop => $loop ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
gkforeach( $gov, [ 1 .. 10 ], |
|
33
|
|
|
|
|
|
|
sub { |
|
34
|
|
|
|
|
|
|
my ( $item, $knext ) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$loop->do_something( on_done => $knext ); |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
sub { $loop->loop_stop }, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$loop->loop_forever; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This L allows functions using it to defer their re-execution |
|
46
|
|
|
|
|
|
|
by using the L C method, meaning it will interleave |
|
47
|
|
|
|
|
|
|
with other IO operations performed by C. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 $gov = CPS::Governor::IOAsync->new( %args ) |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Returns a new instance of a C object. Requires the |
|
58
|
|
|
|
|
|
|
following argument: |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=over 8 |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item loop => IO::Async::Loop |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Reference to the C object. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=back |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Additionally may take any other arguments defined by the |
|
69
|
|
|
|
|
|
|
L class. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new |
|
74
|
|
|
|
|
|
|
{ |
|
75
|
3
|
|
|
3
|
1
|
12693
|
my $class = shift; |
|
76
|
3
|
|
|
|
|
11
|
my %args = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
3
|
50
|
|
|
|
20
|
my $loop = delete $args{loop} or croak "Expected a 'loop'"; |
|
79
|
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
33
|
my $self = $class->SUPER::new( %args ); |
|
81
|
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
134
|
$self->{loop} = $loop; |
|
83
|
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
11
|
return $self; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub later |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
10
|
|
|
10
|
1
|
7455
|
my $self = shift; |
|
90
|
10
|
|
|
|
|
44
|
$self->SUPER::later( @_ ); |
|
91
|
|
|
|
|
|
|
|
|
92
|
10
|
100
|
|
|
|
82
|
return if $self->{later_queued}; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$self->{loop}->later( sub { |
|
95
|
3
|
|
|
3
|
|
2401
|
undef $self->{later_queued}; |
|
96
|
3
|
|
|
|
|
13
|
$self->prod; |
|
97
|
5
|
|
|
|
|
41
|
} ); |
|
98
|
|
|
|
|
|
|
|
|
99
|
5
|
|
|
|
|
109
|
$self->{later_queued} = 1; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Keep perl happy; keep Britain tidy |
|
103
|
|
|
|
|
|
|
1; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |