blib/lib/Evo/Promise/Sync.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« blib/lib/Evo/Promise/Deferred.pm ↑ Summary blib/lib/Evo/Promise/Util.pm »
1 package Evo::Promise::Sync;
2 1 ▶use Evo '-Class *';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 has 'promise', ro;
5 has $_, optional for qw(called v blocking should_resolve);
6  
7 sub reject ($self, $r) {
8 return if $self->called;
9 $self->called(1);
10 $self->blocking ? $self->promise->d_reject($r) : $self->promise->d_reject_continue($r);
11 $self;
12 }
13  
14 sub resolve ($self, $v) {
15 return if $self->called;
16 $self->called(1);
17 $self->blocking ? $self->should_resolve(1)->v($v) : $self->promise->d_resolve_continue($v);
18 $self;
19 }
20  
21 sub try_thenable ($self, $thenable) {
22 $self->blocking(1);
23  
24 # reject drain second time, so don't bother checking "called"
25 my ($res, $rej) = (sub { $self->resolve(@_) }, sub { $self->reject(@_) });
26 eval { $thenable->then($res, $rej); 1; } or $self->reject($@);
27 $self->blocking(0);
28 }
29  
30 1;
31  
32 __END__
« blib/lib/Evo/Promise/Deferred.pm ↑ Summary blib/lib/Evo/Promise/Util.pm »