File Coverage

blib/lib/Evo/Promise/Sync.pm
Criterion Covered Total %
statement 34 34 100.0
branch 16 22 72.7
condition n/a
subroutine 5 5 100.0
pod 1 3 33.3
total 56 64 87.5


line stmt bran cond sub pod time code
1             package Evo::Promise::Sync;
2 12     12   4681 use Evo '-Class *';
  12         25  
  12         63  
3              
4             has 'promise', ro;
5             has $_, optional for qw(called v blocking should_resolve);
6              
7 16 50   16 0 101 sub reject ($self, $r) {
  16 50       43  
  16         23  
  16         23  
  16         23  
8 16 100       67 return if $self->called;
9 7         25 $self->called(1);
10 7 100       46 $self->blocking ? $self->promise->d_reject($r) : $self->promise->d_reject_continue($r);
11 7         25 $self;
12             }
13              
14 16 50   16 0 40 sub resolve ($self, $v) {
  16 50       37  
  16         23  
  16         28  
  16         19  
15 16 100       53 return if $self->called;
16 7         20 $self->called(1);
17 7 100       43 $self->blocking ? $self->should_resolve(1)->v($v) : $self->promise->d_resolve_continue($v);
18 7         17 $self;
19             }
20              
21 15 50   15 1 7299 sub try_thenable ($self, $thenable) {
  15 50       41  
  15         26  
  15         23  
  15         24  
22 15         44 $self->blocking(1);
23              
24             # reject drain second time, so don't bother checking "called"
25 15     15   60 my ($res, $rej) = (sub { $self->resolve(@_) }, sub { $self->reject(@_) });
  15         382  
  13         1133  
26 15 100       33 eval { $thenable->then($res, $rej); 1; } or $self->reject($@);
  15         47  
  13         84  
27 15         67 $self->blocking(0);
28             }
29              
30             1;
31              
32             __END__