line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Promise::AsyncAwait; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
63626
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=encoding utf-8 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Promise::AsyncAwait - Async/await with promises |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Promise::AsyncAwait; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
async sub get_number_plus_1 { |
19
|
|
|
|
|
|
|
my $number = await _get_number_p(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
return 1 + $number; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $p = get_number_plus_1()->then( sub { say "number: " . shift } ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
… and then use whatever mechanism you will for “unrolling” C<$p>. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
L implements JavaScript-like L/L |
31
|
|
|
|
|
|
|
semantics |
32
|
|
|
|
|
|
|
for Perl, but it defaults to using CPAN’s L rather than promises. |
33
|
|
|
|
|
|
|
The two are similar but incompatible. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Use this module for a promise-oriented async/await instead. It’s actually |
36
|
|
|
|
|
|
|
just a shim around Future::AsyncAwait that feeds it configuration options |
37
|
|
|
|
|
|
|
for L promises rather than Future. This yields a friendlier |
38
|
|
|
|
|
|
|
(and likely faster!) experience for those more accustomed to JavaScript |
39
|
|
|
|
|
|
|
promises than to CPAN Future. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This should work with most CPAN promise implementations. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
1
|
|
445
|
use Promise::XS 0.13; |
|
1
|
|
|
|
|
2782
|
|
|
1
|
|
|
|
|
54
|
|
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
8
|
use constant _MIN_FAA_VERSION => 0.47; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
118
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our @ISA; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
BEGIN { |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Future::AsyncAwait loads Future, which we don’t need. |
54
|
1
|
|
|
1
|
|
7
|
local $INC{'Future.pm'} = __FILE__; |
55
|
1
|
|
|
|
|
6
|
local *Future::VERSION = sub { '999.99' }; |
|
1
|
|
|
|
|
1916
|
|
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
19
|
@ISA = ('Future::AsyncAwait'); |
58
|
1
|
|
|
|
|
538
|
require Future::AsyncAwait; |
59
|
1
|
|
|
|
|
106
|
Future::AsyncAwait->VERSION(_MIN_FAA_VERSION); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub import { |
63
|
1
|
|
|
1
|
|
19
|
return $_[0]->SUPER::import( |
64
|
|
|
|
|
|
|
future_class => 'Promise::XS::Promise', |
65
|
|
|
|
|
|
|
@_[1 .. $#_], |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 LICENSE & COPYRIGHT |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Copyright 2021 Gasper Software Consulting. All rights reserved. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This library is licensed under the same license as Perl. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |