| 1 | package Zuzu::Module::Task; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | our $VERSION = '0.007002'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Coro qw( cede ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Time::HiRes qw( time ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Zuzu::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Zuzu::Util::NativeHelpers qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | native_class | ||||||||||||||||||||||||||||||||||||||||||
| 14 | native_function | ||||||||||||||||||||||||||||||||||||||||||
| 15 | native_object | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use Zuzu::Value::Array; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use Zuzu::Value::Boolean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use Zuzu::Value::Task; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2060 | ▶ | sub _yield_task { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_yield_task: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2060 | my ( $runtime ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2060 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $runtime->{"_scheduler"} and $runtime->{"_scheduler"}->can("yield_current_task")
MC/DC0%0/2
defined $runtime->{"_scheduler"} and $runtime->{"_scheduler"}->can("yield_current_task")
defined $runtime->{"_scheduler"}
$runtime->{"_scheduler"}->can("yield_current_task")
Truth table33%1/3
A and B
A= defined $runtime->{"_scheduler"}B= $runtime->{"_scheduler"}->can("yield_current_task")
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | defined $runtime->{_scheduler} | ||||||||||||||||||||||||||||||||||||||||||
| 26 | and $runtime->{_scheduler}->can('yield_current_task') | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 2060 | $runtime->{_scheduler}->yield_current_task; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | cede; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 2059 | return; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 18 | ▶ | sub _task_items { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_task_items: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 18 | my ( $value, $file, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 18 | return @{ $value->items } | |||||||||||||||||||||||||||||||||||||||||
| 41 | 18 | ▶ | if ref($value) and eval { $value->isa('Zuzu::Value::Array') }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value and eval {
do {
$value->isa("Zuzu::Value::Array")
}
}
MC/DC0%0/2
ref $value and eval {
do {
$value->isa("Zuzu::Value::Array")
}
}
ref $value
eval {
do {
$value->isa("Zuzu::Value::Array")
}
}
Truth table33%1/3
A and B
A= ref $valueB= eval {
do {
$value->isa("Zuzu::Value::Array")
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | die Zuzu::Error->new_runtime( | |||||||||||||||||||||||||||||||||||||||||
| 44 | message => 'TypeException: task combinator expects Array', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | file => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | line => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub _runtime_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_runtime_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my ( $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return Zuzu::Error->new_runtime( | |||||||||||||||||||||||||||||||||||||||||
| 54 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | file => '<std/task>', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | line => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 14 | ▶ | sub _task_exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_task_exception: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 14 | my ( $runtime, $class_name, $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 14 | return $runtime->_task_exception( | |||||||||||||||||||||||||||||||||||||||||
| 64 | $class_name, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | $message, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | '<std/task>', | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | ▶ | sub _cancel_reason { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cancel_reason: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | my ( $runtime, $reason ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | return $reason | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if blessed($reason) and eval { $reason->isa('Zuzu::Value::Object') }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($reason) and eval {
do {
$reason->isa("Zuzu::Value::Object")
}
}
MC/DC0%0/2
builtin::blessed($reason) and eval {
do {
$reason->isa("Zuzu::Value::Object")
}
}
builtin::blessed($reason)
eval {
do {
$reason->isa("Zuzu::Value::Object")
}
}
Truth table33%1/3
A and B
A= builtin::blessed($reason)B= eval {
do {
$reason->isa("Zuzu::Value::Object")
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | return _task_exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 'CancelledException', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | defined $reason ? "$reason" : 'Task cancelled', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 11 | ▶ | sub _task_is_done { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_task_is_done: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 11 | my ( $task ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 11 | ▶ | $task->status eq 'fulfilled' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$task->status eq "fulfilled" or $task->status eq "rejected" or $task->status eq "cancelled"
$task->status eq "fulfilled" or $task->status eq "rejected"
MC/DC33%1/3
$task->status eq "fulfilled" or $task->status eq "rejected" or $task->status eq "cancelled"
$task->status eq "fulfilled"
$task->status eq "rejected"
$task->status eq "cancelled"
Truth table50%2/4
A or B or C
A= $task->status eq "fulfilled"B= $task->status eq "rejected"C= $task->status eq "cancelled"
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | or $task->status eq 'rejected' | ||||||||||||||||||||||||||||||||||||||||||
| 89 | or $task->status eq 'cancelled' | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | ▶ | sub _cancel_unfinished { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cancel_unfinished: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | my ( $tasks, $winner, $reason ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | for my $task ( @$tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 97 | 14 | ▶ | next if defined $winner and $task == $winner; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $winner and $task == $winner
MC/DC100%2/2
defined $winner and $task == $winner
defined $winner
$task == $winner
Truth table100%3/3
A and B
A= defined $winnerB= $task == $winner
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | $task->cancel($reason) if !_task_is_done($task); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 20 | ▶ | sub IMPORT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
IMPORT: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 20 | my ( $class, $runtime ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | my $task_class = $runtime->{_builtin_classes}{Task} | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 20 | ▶ | // native_class( name => 'Task' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$runtime->{"_builtin_classes"}{"Task"} // native_class("name", "Task")
MC/DC0%0/2
$runtime->{"_builtin_classes"}{"Task"} // native_class("name", "Task")
$runtime->{"_builtin_classes"}{"Task"}
native_class("name", "Task")
Truth table33%1/3
A // B
A= $runtime->{"_builtin_classes"}{"Task"}B= native_class("name", "Task")
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | my $channel_class = native_class( name => 'Channel' ); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | my $token_class = native_class( name => 'CancellationToken' ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 20 | my $source_class = native_class( name => 'CancellationSource' ); | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | $channel_class->native_constructor( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | my ( $rt, $klass ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | return native_object( | |||||||||||||||||||||||||||||||||||||||||
| 114 | class => $klass, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | slots => { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | queue => [], | ||||||||||||||||||||||||||||||||||||||||||
| 117 | closed => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | queue => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | closed => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 20 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | $source_class->native_constructor( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my ( $rt, $klass ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | my $token = native_object( | |||||||||||||||||||||||||||||||||||||||||
| 129 | class => $token_class, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | slots => { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | cancelled => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | reason => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | tasks => [], | ||||||||||||||||||||||||||||||||||||||||||
| 134 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | cancelled => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | reason => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | tasks => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | return native_object( | |||||||||||||||||||||||||||||||||||||||||
| 142 | class => $klass, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | slots => { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | token => $token, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | token => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 20 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | $task_class->methods->{status} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 153 | name => 'status', | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | return $self->status; | |||||||||||||||||||||||||||||||||||||||||
| 157 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | $task_class->methods->{is_done} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 161 | name => 'is_done', | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | return Zuzu::Value::Boolean->new( | |||||||||||||||||||||||||||||||||||||||||
| 165 | value => _task_is_done($self), | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | $task_class->methods->{done} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 171 | name => 'done', | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | return Zuzu::Value::Boolean->new( | |||||||||||||||||||||||||||||||||||||||||
| 175 | value => _task_is_done($self), | ||||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 177 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | $task_class->methods->{poll} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 181 | name => 'poll', | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | return Zuzu::Value::Boolean->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | value => $self->poll ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | $task_class->methods->{cancel} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 191 | name => 'cancel', | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | my ( $self, $reason ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | $self->cancel( _cancel_reason( $runtime, $reason ) ); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 196 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | $channel_class->methods->{send} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 200 | name => 'send', | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 3 | ▶ | if ( $self->slots->{closed} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | return $runtime->_new_task( | |||||||||||||||||||||||||||||||||||||||||
| 205 | name => 'channel.send', | ||||||||||||||||||||||||||||||||||||||||||
| 206 | status => 'rejected', | ||||||||||||||||||||||||||||||||||||||||||
| 207 | error => _task_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 208 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 'ChannelClosedException', | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 'send on closed channel', | ||||||||||||||||||||||||||||||||||||||||||
| 211 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | push @{ $self->slots->{queue} }, $value; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | return $runtime->_new_task( | |||||||||||||||||||||||||||||||||||||||||
| 216 | name => 'channel.send', | ||||||||||||||||||||||||||||||||||||||||||
| 217 | status => 'fulfilled', | ||||||||||||||||||||||||||||||||||||||||||
| 218 | result => $value, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | $channel_class->methods->{recv} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 224 | name => 'recv', | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 227 | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||||
| 228 | name => 'channel.recv', | ||||||||||||||||||||||||||||||||||||||||||
| 229 | status => 'waiting', | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 94 | ▶ | poll_cb => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 94 | ▶ | if ( @{ $self->slots->{queue} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | my $value = shift @{ $self->slots->{queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | return ( 1, 1, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 92 | ▶ | return ( 1, 1, undef ) if $self->slots->{closed}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 91 | return ( 0, 1, undef ); | |||||||||||||||||||||||||||||||||||||||||
| 237 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 239 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | $channel_class->methods->{close} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 243 | name => 'close', | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | $self->slots->{closed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 248 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | $token_class->methods->{cancelled} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 252 | name => 'cancelled', | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 255 | return Zuzu::Value::Boolean->new( | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | value => $self->slots->{cancelled} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 258 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | $token_class->methods->{reason} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 262 | name => 'reason', | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return $self->slots->{reason}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | $token_class->methods->{throw_if_cancelled} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 270 | name => 'throw_if_cancelled', | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | ▶ | return undef if !$self->slots->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | die $self->slots->{reason} | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | ▶ | // _task_exception( | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->slots->{"reason"} // _task_exception($runtime, "CancelledException", "Task cancelled")
MC/DC0%0/2
$self->slots->{"reason"} // _task_exception($runtime, "CancelledException", "Task cancelled")
$self->slots->{"reason"}
_task_exception($runtime, "CancelledException", "Task cancelled")
Truth table33%1/3
A // B
A= $self->slots->{"reason"}B= _task_exception($runtime, "CancelledException", "Task cancelled")
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 'CancelledException', | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 'Task cancelled', | ||||||||||||||||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 280 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | $token_class->methods->{watch} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 284 | name => 'watch', | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | my ( $self, $task ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | ▶ | die _runtime_error('CancellationToken.watch expects a Task') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
MC/DC0%0/2
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
builtin::blessed($task)
$task->isa("Zuzu::Value::Task")
Truth table33%1/3
A and B
A= builtin::blessed($task)B= $task->isa("Zuzu::Value::Task")
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | if !blessed($task) | ||||||||||||||||||||||||||||||||||||||||||
| 289 | or !$task->isa('Zuzu::Value::Task'); | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | ▶ | if ( $self->slots->{cancelled} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $task->cancel( $self->slots->{reason} ); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | push @{ $self->slots->{tasks} }, $task; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | return $task; | |||||||||||||||||||||||||||||||||||||||||
| 297 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | $source_class->methods->{token} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 301 | name => 'token', | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | return $self->slots->{token}; | |||||||||||||||||||||||||||||||||||||||||
| 305 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | $source_class->methods->{cancel} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 309 | name => 'cancel', | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | my ( $self, $reason ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | my $token = $self->slots->{token}; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | return $self if $token->slots->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | my $cancel_reason = _cancel_reason( $runtime, $reason ); | |||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | $token->slots->{cancelled} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | $token->slots->{reason} = $cancel_reason; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | for my $task ( @{ $token->slots->{tasks} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | $task->cancel($cancel_reason) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
builtin::blessed($task) and $task->isa("Zuzu::Value::Task") and not _task_is_done($task)
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
MC/DC0%0/3
builtin::blessed($task) and $task->isa("Zuzu::Value::Task") and not _task_is_done($task)
builtin::blessed($task)
$task->isa("Zuzu::Value::Task")
not _task_is_done($task)
Truth table25%1/4
A and B and not(C)
A= builtin::blessed($task)B= $task->isa("Zuzu::Value::Task")C= not _task_is_done($task)
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | if blessed($task) | ||||||||||||||||||||||||||||||||||||||||||
| 320 | and $task->isa('Zuzu::Value::Task') | ||||||||||||||||||||||||||||||||||||||||||
| 321 | and !_task_is_done($task); | ||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | $token->slots->{tasks} = []; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 325 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | $source_class->methods->{cancelled} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 329 | name => 'cancelled', | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 332 | return $token_class->methods->{cancelled}{_native}->( | ||||||||||||||||||||||||||||||||||||||||||
| 333 | $self->slots->{token}, | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 335 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | $source_class->methods->{reason} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 339 | name => 'reason', | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | return $self->slots->{token}->slots->{reason}; | |||||||||||||||||||||||||||||||||||||||||
| 343 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | Task => $task_class, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | Channel => $channel_class, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | CancellationToken => $token_class, | ||||||||||||||||||||||||||||||||||||||||||
| 350 | CancellationSource => $source_class, | ||||||||||||||||||||||||||||||||||||||||||
| 351 | resolved => native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 352 | name => 'resolved', | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 10 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 10 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 10 | return $runtime->_new_task( | |||||||||||||||||||||||||||||||||||||||||
| 356 | name => 'resolved', | ||||||||||||||||||||||||||||||||||||||||||
| 357 | status => 'fulfilled', | ||||||||||||||||||||||||||||||||||||||||||
| 358 | result => $value, | ||||||||||||||||||||||||||||||||||||||||||
| 359 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 360 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 362 | failed => native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 363 | name => 'failed', | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | my ( $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | ▶ | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | name => 'failed', | ||||||||||||||||||||||||||||||||||||||||||
| 368 | status => 'rejected', | ||||||||||||||||||||||||||||||||||||||||||
| 369 | error => _task_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 370 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 'Exception', | ||||||||||||||||||||||||||||||||||||||||||
| 372 | defined $message ? "$message" : 'Task failed', | ||||||||||||||||||||||||||||||||||||||||||
| 373 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 374 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 375 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 376 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 377 | sleep => native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 378 | name => 'sleep', | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 54 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 54 | my ( $seconds ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 54 | ▶ | $seconds = 0 + ( defined $seconds ? $seconds : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 54 | ▶ | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | name => 'sleep', | ||||||||||||||||||||||||||||||||||||||||||
| 384 | status => 'sleeping', | ||||||||||||||||||||||||||||||||||||||||||
| 385 | ready_at => time + ( $seconds > 0 ? $seconds : 0 ), | ||||||||||||||||||||||||||||||||||||||||||
| 386 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 387 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 388 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 389 | yield => native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 390 | name => 'yield', | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 5 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||||
| 393 | name => 'yield', | ||||||||||||||||||||||||||||||||||||||||||
| 394 | schedule => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 5 | ▶ | thunk => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 5 | _yield_task($runtime); | |||||||||||||||||||||||||||||||||||||||||
| 397 | 5 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 398 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 400 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 401 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 402 | all => native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 403 | name => 'all', | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 13 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 13 | my ( $tasks ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 13 | my @tasks = _task_items( $tasks, '<std/task>', 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 407 | 13 | for my $task ( @tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 408 | 30 | ▶ | die _runtime_error('all expects only Task values') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
MC/DC0%0/2
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
builtin::blessed($task)
$task->isa("Zuzu::Value::Task")
Truth table33%1/3
A and B
A= builtin::blessed($task)B= $task->isa("Zuzu::Value::Task")
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | if !blessed($task) | ||||||||||||||||||||||||||||||||||||||||||
| 410 | or !$task->isa('Zuzu::Value::Task'); | ||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 13 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 413 | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||||
| 414 | name => 'all', | ||||||||||||||||||||||||||||||||||||||||||
| 415 | schedule => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | on_cancel => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | my ( $task ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | _cancel_unfinished( \@tasks, undef, $task->error ); | |||||||||||||||||||||||||||||||||||||||||
| 419 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 13 | ▶ | thunk => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 13 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 422 | 1984 | for my $i ( 0 .. $#tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 423 | 4076 | ▶ | next if exists $values[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 3897 | my $task = $tasks[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 3897 | ▶ | next if !$task->poll; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 27 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 27 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 428 | 27 | $value = $task->await; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 26 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 430 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 27 | ▶ | if ( !$ok ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | _cancel_unfinished( \@tasks, $task ); | |||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | die $@; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 26 | $values[$i] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | last | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 1983 | ▶ | if !grep { !exists $values[$_] } 0 .. $#tasks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 1972 | _yield_task($runtime); | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 11 | return Zuzu::Value::Array->new( items => \@values ); | |||||||||||||||||||||||||||||||||||||||||
| 442 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 13 | ); | |||||||||||||||||||||||||||||||||||||||||
| 444 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 445 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 446 | race => native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 447 | name => 'race', | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.9
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 5 | my ( $tasks ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 5 | my @tasks = _task_items( $tasks, '<std/task>', 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 451 | 5 | ▶ | die _runtime_error('race expects at least one task') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | if !@tasks; | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 5 | for my $task ( @tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 454 | 10 | ▶ | die _runtime_error('race expects only Task values') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
MC/DC0%0/2
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
builtin::blessed($task)
$task->isa("Zuzu::Value::Task")
Truth table33%1/3
A and B
A= builtin::blessed($task)B= $task->isa("Zuzu::Value::Task")
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | if !blessed($task) | ||||||||||||||||||||||||||||||||||||||||||
| 456 | or !$task->isa('Zuzu::Value::Task'); | ||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||||
| 459 | name => 'race', | ||||||||||||||||||||||||||||||||||||||||||
| 460 | schedule => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | on_cancel => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my ( $task ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | _cancel_unfinished( \@tasks, undef, $task->error ); | |||||||||||||||||||||||||||||||||||||||||
| 464 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 5 | ▶ | thunk => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 5 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 467 | 88 | for my $task ( @tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 468 | 174 | ▶ | next if !$task->poll; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 5 | _cancel_unfinished( | |||||||||||||||||||||||||||||||||||||||||
| 470 | \@tasks, | ||||||||||||||||||||||||||||||||||||||||||
| 471 | $task, | ||||||||||||||||||||||||||||||||||||||||||
| 472 | _task_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 473 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 'CancelledException', | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 'race loser cancelled', | ||||||||||||||||||||||||||||||||||||||||||
| 476 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 477 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 5 | return $task->await; | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 83 | _yield_task($runtime); | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 484 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 485 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 486 | timeout => native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 487 | name => 'timeout', | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 3 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 3 | my ( $seconds, $task ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 3 | ▶ | $seconds = 0 + ( defined $seconds ? $seconds : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 3 | ▶ | die _runtime_error('timeout expects a Task') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
MC/DC0%0/2
builtin::blessed($task) and $task->isa("Zuzu::Value::Task")
builtin::blessed($task)
$task->isa("Zuzu::Value::Task")
Truth table33%1/3
A and B
A= builtin::blessed($task)B= $task->isa("Zuzu::Value::Task")
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | if !blessed($task) | ||||||||||||||||||||||||||||||||||||||||||
| 493 | or !$task->isa('Zuzu::Value::Task'); | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 3 | ▶ | my $deadline = time + ( $seconds > 0 ? $seconds : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||||
| 496 | name => 'timeout', | ||||||||||||||||||||||||||||||||||||||||||
| 497 | status => 'waiting', | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 152 | ▶ | poll_cb => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 152 | ▶ | if ( $task->poll ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | $value = $task->await; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 504 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | return ( 1, 1, $value ) if $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return ( 1, 0, $@ ); | |||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 152 | ▶ | if ( time >= $deadline ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 3 | my $timeout = _task_exception( | |||||||||||||||||||||||||||||||||||||||||
| 510 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 'TimeoutException', | ||||||||||||||||||||||||||||||||||||||||||
| 512 | "timeout after ${seconds}s", | ||||||||||||||||||||||||||||||||||||||||||
| 513 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 3 | $task->cancel($timeout); | |||||||||||||||||||||||||||||||||||||||||
| 515 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 3 | 1, | |||||||||||||||||||||||||||||||||||||||||
| 517 | 0, | ||||||||||||||||||||||||||||||||||||||||||
| 518 | $timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 519 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 149 | return ( 0, 1, undef ); | |||||||||||||||||||||||||||||||||||||||||
| 522 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 524 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 20 | ), | |||||||||||||||||||||||||||||||||||||||||
| 526 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | B<< Zuzu::Module::Task >> is copyright Toby Inkster. | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | It is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 538 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 539 | License version 2. | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | =cut | ||||||||||||||||||||||||||||||||||||||||||