| 1 | package IO::Concurrent::Runner::Select; | ||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use IO::Select; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use Carp (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | $Carp::Internal{+__PACKAGE__}++; | |||||||||||
| 9 | |||||||||||||
| 10 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 11 | 0 | my ($class, $contexts, $opts) = @_; | |||||||||||
| 12 | 0 | ▶ | $opts ||= {}; | ||||||||||
|
Condition0%0/2
$opts ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||
| 13 | |||||||||||||
| 14 | 0 | bless { | |||||||||||
| 15 | %$opts, | ||||||||||||
| 16 | contexts => $contexts, | ||||||||||||
| 17 | } => $class; | ||||||||||||
| 18 | } | ||||||||||||
| 19 | |||||||||||||
| 20 | 0 | ▶ | sub run { | ||||||||||
|
Subroutine
run: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||
| 21 | 0 | my $self = shift; | |||||||||||
| 22 | |||||||||||||
| 23 | 0 | my %context_map = map { $_->handler->fileno => $_ } @{ $self->{contexts} }; | |||||||||||
| 24 | |||||||||||||
| 25 | 0 | my @aborted_contexts; | |||||||||||
| 26 | 0 | ▶ | while (%context_map) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 0 | my ($readable, $writable) = do { | |||||||||||
| 28 | 0 | my @readers = map { $_->handler } grep { $_->current_actor->is_waiting_for_readable } values %context_map; | |||||||||||
| 29 | 0 | my @writers = map { $_->handler } grep { $_->current_actor->is_waiting_for_writable } values %context_map; | |||||||||||
| 30 | 0 | IO::Select->select( | |||||||||||
| 31 | IO::Select->new(@readers), | ||||||||||||
| 32 | IO::Select->new(@writers), | ||||||||||||
| 33 | undef, | ||||||||||||
| 34 | 0 | ||||||||||||
| 35 | ) | ||||||||||||
| 36 | }; | ||||||||||||
| 37 | |||||||||||||
| 38 | 0 | ▶ | if (defined $writable) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 0 | my @writable_context = @context_map{map $_->fileno, @$writable}; | |||||||||||
| 40 | 0 | for my $context (@writable_context) { | |||||||||||
| 41 | 0 | $context->current_actor->callback->($context); | |||||||||||
| 42 | 0 | ▶ | push @aborted_contexts => $context if $context->error; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 0 | ▶ | delete $context_map{$context->handler->fileno} if $context->is_completed; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | } | ||||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 0 | ▶ | if (defined $readable) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 0 | my @readable_context = @context_map{map $_->fileno, @$readable}; | |||||||||||
| 49 | 0 | for my $context (@readable_context) { | |||||||||||
| 50 | 0 | $context->current_actor->callback->($context); | |||||||||||
| 51 | 0 | ▶ | push @aborted_contexts => $context if $context->error; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 0 | ▶ | delete $context_map{$context->handler->fileno} if $context->is_completed; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | } | ||||||||||||
| 54 | } | ||||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 0 | for my $context (@aborted_contexts) { | |||||||||||
| 58 | 0 | $self->{on_error}->($context); | |||||||||||
| 59 | } | ||||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 1 | 1; | |||||||||||
| 63 | __END__ | ||||||||||||