line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package fs::Promises::Utils; |
2
|
2
|
|
|
2
|
|
1312
|
use v5.24; |
|
2
|
|
|
|
|
8
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
9
|
use AnyEvent (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
27
|
|
5
|
2
|
|
|
2
|
|
11
|
use AnyEvent::XSPromises (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
6
|
2
|
|
|
2
|
|
11
|
use Scalar::Util qw(blessed); |
|
2
|
|
|
|
|
26
|
|
|
2
|
|
|
|
|
118
|
|
7
|
2
|
|
|
2
|
|
13
|
use Exporter qw(import); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
801
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(await p_while then); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub await ($) { |
11
|
10
|
|
|
10
|
0
|
24
|
my $p = shift; |
12
|
10
|
|
|
|
|
278
|
my $cv = AnyEvent->condvar; |
13
|
|
|
|
|
|
|
$p->then( |
14
|
7
|
|
|
7
|
|
1313
|
sub { $cv->send(@_) }, |
15
|
3
|
|
|
3
|
|
1887
|
sub { $cv->croak(@_) }, |
16
|
10
|
|
|
|
|
467
|
); |
17
|
10
|
|
|
|
|
46
|
return $cv->recv; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
0
|
sub then (&) { return $_[0] } |
21
|
|
|
|
|
|
|
sub p_while (&$) { |
22
|
1
|
|
|
1
|
0
|
1506
|
my ($while_cond, $cb) = @_; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
21
|
my $d = AnyEvent::XSPromises::deferred(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub { |
27
|
86
|
|
|
86
|
|
169
|
my $do_while = __SUB__; |
28
|
86
|
|
|
|
|
200
|
my $cond = $while_cond->(); |
29
|
86
|
50
|
33
|
|
|
1554
|
$cond = AnyEvent::XSPromises::resolved($cond) if !blessed($cond) || !$cond->can('then'); |
30
|
|
|
|
|
|
|
return $cond->then(sub { |
31
|
86
|
100
|
|
|
|
351
|
return unless defined($_[0]); |
32
|
85
|
|
|
|
|
225
|
$cb->($_[0]); |
33
|
85
|
|
|
|
|
56571
|
$do_while->(); |
34
|
|
|
|
|
|
|
}) |
35
|
1
|
|
|
1
|
|
9
|
}->()->finally(sub { $d->resolve }); |
|
86
|
|
|
|
|
1151
|
|
|
1
|
|
|
|
|
11
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
31
|
return $d->promise; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|