File: promise_all_race.t

package info (click to toggle)
libpromise-xs-perl 0.20-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: perl: 1,097; ansic: 355; makefile: 3
file content (77 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;

use Promise::XS;

my $p1 = Promise::XS::resolved(2, 3);
my $p2 = Promise::XS::resolved(4);

$p1->all($p1, $p2)->then( sub {
    my (@got)  = @_;

    is_deeply(
        \@got,
        [
            [ 2, 3 ],
            [ 4 ],
        ],
        'all() works as a method of the promise object',
    );
} );

$p1->all($p1, 'bar')->then( sub {
    my (@got)  = @_;

    is_deeply(
        \@got,
        [
            [ 2, 3 ],
            [ 'bar' ],
        ],
        'all() works as a method of the promise object and string',
    );
} );


Promise::XS::Promise->all($p1, $p2)->then( sub {
    my (@got)  = @_;

    is_deeply(
        \@got,
        [
            [ 2, 3 ],
            [ 4 ],
        ],
        'all() works as a class method',
    );
} );

#----------------------------------------------------------------------

$p1->race($p1, $p2)->then( sub {
    my (@got)  = @_;

    is_deeply(
        \@got,
        [ 2, 3 ],
        'race() works as a method of the promise object',
    );
} );

Promise::XS::Promise->race($p1, $p2)->then( sub {
    my (@got)  = @_;

    is_deeply(
        \@got,
        [ 2, 3 ],
        'race() works as a class method',
    );
} );

done_testing();

1;