File Coverage

blib/lib/Job/Async/Worker/Memory.pm
Criterion Covered Total %
statement 26 26 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 10 10 100.0
pod 0 3 0.0
total 38 44 86.3


line stmt bran cond sub pod time code
1             package Job::Async::Worker::Memory;
2              
3 2     2   991 use strict;
  2         5  
  2         58  
4 2     2   10 use warnings;
  2         2  
  2         55  
5              
6 2     2   13 use parent qw(Job::Async::Worker);
  2         4  
  2         11  
7              
8             our $VERSION = '0.003'; # VERSION
9              
10             =head1 NAME
11              
12             Job::Async::Worker::Memory - basic in-memory job worker for L
13              
14             =head1 DESCRIPTION
15              
16             This is intended as an example, and for testing code. It's not
17             very useful in a real application.
18              
19             =cut
20              
21 2     2   144 use Future::Utils qw(repeat);
  2         5  
  2         639  
22              
23 1     1 0 7 sub start { Future->done }
24              
25             sub trigger {
26 2     2 0 368 my ($self) = @_;
27             $self->{active} ||= (repeat {
28 2532     2532   49774 my $loop = $self->loop;
29 2532         12603 my $f = $loop->new_future;
30             $self->loop->later(sub {
31 2532 50       281381 if(my $job = shift @Job::Async::Memory::PENDING_JOBS) {
32 2532         5175 $self->process($job);
33             }
34 2532         367985 $f->done;
35 2532         43878 });
36 2532         63428 $f;
37 2532     2532   158723 } while => sub { 0+@Job::Async::Memory::PENDING_JOBS })->on_ready(sub {
38             delete $self->{active}
39 2     2   187 })
40 2   33     27 }
41              
42             sub process {
43 2532     2532 0 4091 my ($self, $job) = @_;
44 2532         6604 $self->jobs->emit($job);
45             }
46              
47             1;
48              
49             =head1 AUTHOR
50              
51             Tom Molesworth
52              
53             =head1 LICENSE
54              
55             Copyright Tom Molesworth 2016-2017. Licensed under the same terms as Perl itself.
56