line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package fs::Promises::Utils; |
2
|
1
|
|
|
1
|
|
548
|
use v5.24; |
|
1
|
|
|
|
|
4
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use AnyEvent (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
5
|
1
|
|
|
1
|
|
5
|
use AnyEvent::XSPromises (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
6
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
7
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
354
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(await p_while then); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub await ($) { |
11
|
6
|
|
|
6
|
0
|
14
|
my $p = shift; |
12
|
6
|
|
|
|
|
154
|
my $cv = AnyEvent->condvar; |
13
|
|
|
|
|
|
|
$p->then( |
14
|
5
|
|
|
5
|
|
255
|
sub { $cv->send(@_) }, |
15
|
1
|
|
|
1
|
|
69
|
sub { $cv->croak(@_) }, |
16
|
6
|
|
|
|
|
321
|
); |
17
|
6
|
|
|
|
|
27
|
return $cv->recv; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
0
|
sub then (&) { return $_[0] } |
21
|
|
|
|
|
|
|
sub p_while (&$) { |
22
|
1
|
|
|
1
|
0
|
1571
|
my ($while_cond, $cb) = @_; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
9
|
my $d = AnyEvent::XSPromises::deferred(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub { |
27
|
71
|
|
|
71
|
|
138
|
my $do_while = __SUB__; |
28
|
71
|
|
|
|
|
171
|
my $cond = $while_cond->(); |
29
|
71
|
50
|
33
|
|
|
1296
|
$cond = AnyEvent::XSPromises::resolved($cond) if !blessed($cond) || !$cond->can('then'); |
30
|
|
|
|
|
|
|
return $cond->then(sub { |
31
|
71
|
100
|
|
|
|
270
|
return unless defined($_[0]); |
32
|
70
|
|
|
|
|
184
|
$cb->($_[0]); |
33
|
70
|
|
|
|
|
45903
|
$do_while->(); |
34
|
|
|
|
|
|
|
}) |
35
|
1
|
|
|
1
|
|
9
|
}->()->finally(sub { $d->resolve }); |
|
71
|
|
|
|
|
913
|
|
|
1
|
|
|
|
|
9
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
30
|
return $d->promise; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|