line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Promises6::Deferred; |
2
|
30
|
|
|
30
|
|
16775
|
use Evo -class, -modern; |
|
30
|
|
|
|
|
32
|
|
|
30
|
|
|
|
|
144
|
|
3
|
30
|
|
|
30
|
|
6184
|
use Promises6::Util ':all'; |
|
30
|
|
|
|
|
35
|
|
|
30
|
|
|
|
|
16703
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# [state, val] |
6
|
|
|
|
|
|
|
has [qw(result builder)]; |
7
|
|
|
|
|
|
|
has subscribers => sub { [] }; |
8
|
|
|
|
|
|
|
has 'is_adaptor'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# public methods ----------- |
11
|
266
|
50
|
|
266
|
1
|
1439
|
sub promise($self) { $self->builder->promise(deferred => $self) } |
|
266
|
50
|
|
|
|
363
|
|
|
266
|
|
|
|
|
197
|
|
|
266
|
|
|
|
|
187
|
|
|
266
|
|
|
|
|
655
|
|
12
|
|
|
|
|
|
|
|
13
|
232
|
50
|
|
232
|
1
|
3007
|
sub resolve($self, $val) { |
|
232
|
50
|
|
|
|
342
|
|
|
232
|
|
|
|
|
171
|
|
|
232
|
|
|
|
|
194
|
|
|
232
|
|
|
|
|
170
|
|
14
|
232
|
100
|
|
|
|
442
|
return if $self->is_adaptor; |
15
|
230
|
|
|
|
|
514
|
$self->builder->resolver->resolve($self, $val); |
16
|
230
|
|
|
|
|
914
|
$self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# don't try to resolve |
20
|
49
|
50
|
|
49
|
1
|
531
|
sub reject($self, $reason) { |
|
49
|
50
|
|
|
|
90
|
|
|
49
|
|
|
|
|
62
|
|
|
49
|
|
|
|
|
45
|
|
|
49
|
|
|
|
|
49
|
|
21
|
49
|
100
|
|
|
|
132
|
return if $self->is_adaptor; |
22
|
47
|
|
|
|
|
91
|
$self->change_state(REJECTED, $reason); |
23
|
47
|
|
|
|
|
85
|
$self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
29
|
50
|
|
29
|
1
|
78
|
sub notify($self, $val) { |
|
29
|
50
|
|
|
|
55
|
|
|
29
|
|
|
|
|
23
|
|
|
29
|
|
|
|
|
19
|
|
|
29
|
|
|
|
|
22
|
|
27
|
29
|
50
|
|
|
|
35
|
$self->state eq PENDING && $self->broadcast(PROGRESS, $val); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# implementation methods ----------- |
31
|
483
|
50
|
|
483
|
1
|
689
|
sub state($self) { $self->result or return PENDING; $self->result->[0] } |
|
483
|
50
|
|
|
|
574
|
|
|
483
|
100
|
|
|
|
339
|
|
|
483
|
|
|
|
|
319
|
|
|
483
|
|
|
|
|
1498
|
|
|
72
|
|
|
|
|
249
|
|
32
|
|
|
|
|
|
|
|
33
|
248
|
50
|
|
248
|
1
|
365
|
sub change_state($self, $state, $val) { |
|
248
|
50
|
|
|
|
338
|
|
|
248
|
|
|
|
|
176
|
|
|
248
|
|
|
|
|
177
|
|
|
248
|
|
|
|
|
175
|
|
|
248
|
|
|
|
|
172
|
|
34
|
248
|
100
|
|
|
|
299
|
return unless $self->state == PENDING; |
35
|
237
|
|
|
|
|
669
|
$self->result([$state, $val])->broadcast($state, $val); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# prevent future errors, don't do delete $self->{subscribers} |
38
|
237
|
|
|
|
|
976
|
$self->{subscribers} = 0; |
39
|
237
|
|
|
|
|
455
|
$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
266
|
50
|
|
266
|
1
|
388
|
sub broadcast($self, $state, $val) { |
|
266
|
50
|
|
|
|
332
|
|
|
266
|
|
|
|
|
209
|
|
|
266
|
|
|
|
|
168
|
|
|
266
|
|
|
|
|
200
|
|
|
266
|
|
|
|
|
395
|
|
43
|
266
|
|
|
|
|
414
|
$self->send_msg($_, $state, $val) for $self->subscribers->@*; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# you can use loop here |
48
|
173
|
50
|
|
173
|
1
|
308
|
sub send_msg($self, $listener, $state, $val) { |
|
173
|
50
|
|
|
|
238
|
|
|
173
|
|
|
|
|
143
|
|
|
173
|
|
|
|
|
123
|
|
|
173
|
|
|
|
|
126
|
|
|
173
|
|
|
|
|
132
|
|
|
173
|
|
|
|
|
113
|
|
49
|
173
|
|
|
|
|
309
|
$listener->get_msg($state, $val); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
156
|
50
|
|
156
|
1
|
855
|
sub subscribe($self, $listener) { |
|
156
|
50
|
|
|
|
214
|
|
|
156
|
|
|
|
|
133
|
|
|
156
|
|
|
|
|
142
|
|
|
156
|
|
|
|
|
123
|
|
53
|
156
|
100
|
|
|
|
234
|
return push $self->subscribers->@*, $listener if $self->state eq PENDING; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# already resolved |
56
|
37
|
|
|
|
|
100
|
$self->send_msg($listener, $self->result->@*); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |