line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Promise::ES6::IOAsync; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
133253
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=encoding utf-8 |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Promise::ES6::IOAsync - L promises for L |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $loop_guard = Promise::ES6::IOAsync::SET_LOOP($loop); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Now use Promise::ES6::IOAsync as you would plain Promise::ES6. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DEPRECATION NOTICE |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module is deprecated and will go away eventually. |
23
|
|
|
|
|
|
|
Use C instead, as described in L’s documentation. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This module exposes the same functionality as L |
28
|
|
|
|
|
|
|
but for L rather than L. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Whereas L assumes that an event loop is global, L |
31
|
|
|
|
|
|
|
allows multiple concurrent event loops. In order to accommodate this |
32
|
|
|
|
|
|
|
difference in architecture, this module requires an active L |
33
|
|
|
|
|
|
|
object before it can be used. See C below. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
7
|
use parent qw(Promise::ES6::EventLoopBase); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $LOOP; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 FUNCTIONS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 $guard = SET_LOOP( $LOOP ) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Sets this module’s active L object. This is a internal |
50
|
|
|
|
|
|
|
global; if you try to set a loop while one is already set, an exception |
51
|
|
|
|
|
|
|
is thrown. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This returns an opaque object that, when DESTROY()ed, will clear this |
54
|
|
|
|
|
|
|
module’s internal loop. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub SET_LOOP { |
59
|
0
|
0
|
|
0
|
1
|
|
die "Loop is already set!" if $LOOP; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if (!defined wantarray) { |
62
|
0
|
|
|
|
|
|
my $fn = (caller 0)[3]; |
63
|
0
|
|
|
|
|
|
die "Void context to $fn() is useless!"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$LOOP = $_[0]; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return bless [ \$LOOP ], 'Promise::ES6::IOAsync::_GUARD'; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _postpone { |
72
|
0
|
0
|
|
0
|
|
|
die "Need active loop … did you call SET_LOOP() first?" if !$LOOP; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $LOOP->later( $_[1] ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package Promise::ES6::IOAsync::_GUARD; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub DESTROY { |
82
|
0
|
|
|
0
|
|
|
${ $_[0][0] } = undef; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |