File: start_child.t

package info (click to toggle)
libparallel-forkmanager-perl 2.03-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 268 kB
  • sloc: perl: 475; xml: 291; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;

use Test::More tests => 2;

use Parallel::ForkManager;

subtest 'classic' => sub {
    my @results;

    my $fm = Parallel::ForkManager->new(4);

    @results = ();

    $fm->run_on_finish(sub{ 
        push @results, @{$_[5]};
    });

    for ( 1..5 ) {
        $fm->start and next;
        $fm->finish(0, [ $_ ]);
    }

    $fm->wait_all_children;

    is_deeply [ sort @results ] => [ 1..5 ], 'get expected results';
};

subtest 'callback' => sub {
    my @results;

    my $fm = Parallel::ForkManager->new(4);

    @results = ();

    $fm->run_on_finish(sub{ 
        push @results, @{$_[5]};
    });

    for ( 1..5 ) {
        $fm->start_child(sub{
            return [ $_ ];
        });
    }

    $fm->wait_all_children;

    is_deeply [ sort @results ] => [ 1..5 ], 'get expected results';
};