| 1 | package DBIO::Async::Future; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The Future a caller waits on for a pool connection, blocking via Future::IO | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 44 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 44 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 44 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 44 | ▶ | use base 'Future'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 44 | ▶ | use Future::IO (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 44 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 78 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 78 | my $proto = shift; | |||||||||||||||||||||||||||
| 18 | 78 | my $self = $proto->SUPER::new(@_); | |||||||||||||||||||||||||||
| 19 | 78 | ▶ | if (ref $proto and my $mark = $proto->udata("dbio_async_pool_wait")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $proto and my $mark = $proto->udata("dbio_async_pool_wait")
MC/DC50%1/2
ref $proto and my $mark = $proto->udata("dbio_async_pool_wait")
ref $proto
my $mark = $proto->udata("dbio_async_pool_wait")
Truth table66%2/3
A and B
A= ref $protoB= my $mark = $proto->udata("dbio_async_pool_wait")
| |||||||||||||||||||||||||||||
| 20 | 49 | $self->set_udata(dbio_async_pool_wait => $mark); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 78 | return $self; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 29 | ▶ | sub mark_pool_wait { | ||||||||||||||||||||||||||
|
Subroutine
mark_pool_wait: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 29 | my ($self, $pool) = @_; | |||||||||||||||||||||||||||
| 28 | 29 | my $mark = [ $pool, $self ]; | |||||||||||||||||||||||||||
| 29 | 29 | Scalar::Util::weaken($_) for @$mark; | |||||||||||||||||||||||||||
| 30 | 29 | $self->set_udata(dbio_async_pool_wait => $mark); | |||||||||||||||||||||||||||
| 31 | 29 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 6 | ▶ | sub await { | ||||||||||||||||||||||||||
|
Subroutine
await: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 6 | ▶ | return $self if $self->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # A pending Future of the implementation's class, made by cloning one of its | ||||||||||||||||||||||||||||
| 40 | # own: its await runs the implementation's loop until it is ready. The | ||||||||||||||||||||||||||||
| 41 | # sleep it is cloned from is left to elapse -- this dist cancels a Future in | ||||||||||||||||||||||||||||
| 42 | # one place only (Storage _let_go, t/13) -- and the tick is never cancelled, | ||||||||||||||||||||||||||||
| 43 | # only dropped with this Future when the wait dies. | ||||||||||||||||||||||||||||
| 44 | 6 | my $tick = Future::IO->sleep(0)->new; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 6 | ▶ | $self->on_ready(sub { $tick->done unless $tick->is_ready }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 6 | my $ok = eval { $tick->await; 1 }; | |||||||||||||||||||||||||||
| 49 | 6 | my $error = $@; | |||||||||||||||||||||||||||
| 50 | 6 | ▶ | return $self if $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | $self->_withdraw_dying_wait($error); | |||||||||||||||||||||||||||
| 53 | 1 | die $error; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | ▶ | sub _withdraw_dying_wait { | ||||||||||||||||||||||||||
|
Subroutine
_withdraw_dying_wait: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||
| 57 | 1 | my ($self, $error) = @_; | |||||||||||||||||||||||||||
| 58 | 1 | ▶ | my $mark = $self->udata("dbio_async_pool_wait") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 1 | my ($pool, $waiter) = @$mark; | |||||||||||||||||||||||||||
| 60 | 1 | ▶ | return unless $pool && $waiter; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pool and $waiter
MC/DC0%0/2
$pool and $waiter
$pool
$waiter
Truth table33%1/3
A and B
A= $poolB= $waiter
| |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | $waiter->fail($error) if $pool->_withdraw_waiter($waiter); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | return; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 44 | 1; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||