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   844 use strict;
  2         4  
  2         58  
4 2     2   8 use warnings;
  2         3  
  2         54  
5              
6 2     2   8 use parent qw(Job::Async::Worker);
  2         10  
  2         13  
7              
8             our $VERSION = '0.002'; # 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   112 use Future::Utils qw(repeat);
  2         5  
  2         477  
22              
23 1     1 0 5 sub start { Future->done }
24              
25             sub trigger {
26 2     2 0 258 my ($self) = @_;
27             $self->{active} ||= (repeat {
28 2532     2532   42170 my $loop = $self->loop;
29 2532         10460 my $f = $loop->new_future;
30             $self->loop->later(sub {
31 2532 50       231612 if(my $job = shift @Job::Async::Memory::PENDING_JOBS) {
32 2532         4695 $self->process($job);
33             }
34 2532         300023 $f->done;
35 2532         37050 });
36 2532         51281 $f;
37 2532     2532   128143 } while => sub { 0+@Job::Async::Memory::PENDING_JOBS })->on_ready(sub {
38             delete $self->{active}
39 2     2   134 })
40 2   33     24 }
41              
42             sub process {
43 2532     2532 0 3577 my ($self, $job) = @_;
44 2532         5278 $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