line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Promises6::Deferred; |
2
|
30
|
|
|
30
|
|
11442
|
use Evo::Base -base; |
|
30
|
|
|
|
|
48
|
|
|
30
|
|
|
|
|
180
|
|
3
|
30
|
|
|
30
|
|
6579
|
use Promises6::Util ':all'; |
|
30
|
|
|
|
|
49
|
|
|
30
|
|
|
|
|
23787
|
|
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
|
2116
|
sub promise($self) { $self->builder->promise(deferred => $self) } |
|
266
|
50
|
|
|
|
505
|
|
|
266
|
|
|
|
|
272
|
|
|
266
|
|
|
|
|
252
|
|
|
266
|
|
|
|
|
4702
|
|
12
|
|
|
|
|
|
|
|
13
|
232
|
50
|
|
232
|
1
|
4998
|
sub resolve($self, $val) { |
|
232
|
50
|
|
|
|
413
|
|
|
232
|
|
|
|
|
250
|
|
|
232
|
|
|
|
|
232
|
|
|
232
|
|
|
|
|
226
|
|
14
|
232
|
100
|
|
|
|
4406
|
return if $self->is_adaptor; |
15
|
230
|
|
|
|
|
4730
|
$self->builder->resolver->resolve($self, $val); |
16
|
230
|
|
|
|
|
1559
|
$self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# don't try to resolve |
20
|
49
|
50
|
|
49
|
1
|
789
|
sub reject($self, $reason) { |
|
49
|
50
|
|
|
|
125
|
|
|
49
|
|
|
|
|
72
|
|
|
49
|
|
|
|
|
69
|
|
|
49
|
|
|
|
|
56
|
|
21
|
49
|
100
|
|
|
|
947
|
return if $self->is_adaptor; |
22
|
47
|
|
|
|
|
356
|
$self->change_state(REJECTED, $reason); |
23
|
47
|
|
|
|
|
136
|
$self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
29
|
50
|
|
29
|
1
|
94
|
sub notify($self, $val) { |
|
29
|
50
|
|
|
|
53
|
|
|
29
|
|
|
|
|
23
|
|
|
29
|
|
|
|
|
24
|
|
|
29
|
|
|
|
|
32
|
|
27
|
29
|
50
|
|
|
|
40
|
$self->state eq PENDING && $self->broadcast(PROGRESS, $val); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# implementation methods ----------- |
31
|
483
|
50
|
|
483
|
1
|
1036
|
sub state($self) { $self->result or return PENDING; $self->result->[0] } |
|
483
|
50
|
|
|
|
736
|
|
|
483
|
100
|
|
|
|
473
|
|
|
483
|
|
|
|
|
405
|
|
|
483
|
|
|
|
|
8267
|
|
|
72
|
|
|
|
|
1344
|
|
32
|
|
|
|
|
|
|
|
33
|
248
|
50
|
|
248
|
1
|
733
|
sub change_state($self, $state, $val) { |
|
248
|
50
|
|
|
|
811
|
|
|
248
|
|
|
|
|
255
|
|
|
248
|
|
|
|
|
237
|
|
|
248
|
|
|
|
|
236
|
|
|
248
|
|
|
|
|
217
|
|
34
|
248
|
100
|
|
|
|
450
|
return unless $self->state == PENDING; |
35
|
237
|
|
|
|
|
5025
|
$self->result([$state, $val])->broadcast($state, $val); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# prevent future errors, don't do delete $self->{subscribers} |
38
|
237
|
|
|
|
|
1324
|
$self->{subscribers} = 0; |
39
|
237
|
|
|
|
|
614
|
$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
266
|
50
|
|
266
|
1
|
1763
|
sub broadcast($self, $state, $val) { |
|
266
|
50
|
|
|
|
449
|
|
|
266
|
|
|
|
|
260
|
|
|
266
|
|
|
|
|
249
|
|
|
266
|
|
|
|
|
244
|
|
|
266
|
|
|
|
|
270
|
|
43
|
266
|
|
|
|
|
4308
|
$self->send_msg($_, $state, $val) for $self->subscribers->@*; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# you can use loop here |
48
|
173
|
50
|
|
173
|
1
|
436
|
sub send_msg($self, $listener, $state, $val) { |
|
173
|
50
|
|
|
|
312
|
|
|
173
|
|
|
|
|
212
|
|
|
173
|
|
|
|
|
199
|
|
|
173
|
|
|
|
|
202
|
|
|
173
|
|
|
|
|
206
|
|
|
173
|
|
|
|
|
151
|
|
49
|
173
|
|
|
|
|
445
|
$listener->get_msg($state, $val); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
156
|
50
|
|
156
|
1
|
1214
|
sub subscribe($self, $listener) { |
|
156
|
50
|
|
|
|
312
|
|
|
156
|
|
|
|
|
161
|
|
|
156
|
|
|
|
|
150
|
|
|
156
|
|
|
|
|
141
|
|
53
|
156
|
100
|
|
|
|
387
|
return push $self->subscribers->@*, $listener if $self->state eq PENDING; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# already resolved |
56
|
37
|
|
|
|
|
725
|
$self->send_msg($listener, $self->result->@*); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |