File Coverage

blib/lib/Mojo/Promise/Role/None.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Mojo::Promise::Role::None;
2 1     1   785 use Mojo::Base '-role';
  1         3  
  1         8  
3              
4 1     1   523 use strict;
  1         3  
  1         226  
5              
6             our $VERSION = '1.003';
7              
8             =encoding utf8
9              
10             =head1 NAME
11              
12             Mojo::Promise::Role::Any - Fulfill when all of the promises are rejected
13              
14             =head1 SYNOPSIS
15              
16             use Mojo::Promise;
17              
18             my $none_promise = Mojo::Promise
19             ->with_roles( '+None' )
20             ->none( @promises );
21              
22             =head1 DESCRIPTION
23              
24             Make a new promise that fulfills when all promises are rejected, and
25             rejects otherwise.
26              
27             =over 4
28              
29             =item none( @promises )
30              
31             Takes a lists of promises (or thenables) and returns another promise
32             that fulfills when all of the promises are rejected.
33              
34             If none of the promises reject, the none promise rejects. If all of the
35             promises resolve then this is rejected.
36              
37             If you pass no promises, the none promise fulfills.
38              
39             =cut
40              
41             sub none {
42 3     3 1 14710 my( $self, @promises ) = @_;
43 3         41 my $none = $self->new;
44              
45 3         99 my $count = 0;
46             $_->then(
47 1     1   637 sub { $none->reject( @_ ) },
48 6 100   6   1478 sub { $count++; $none->resolve if $count == @promises }
  6         41  
49 3         32 ) foreach @promises;
50              
51 3 100       646 return @promises ? $none : $none->resolve;
52             }
53              
54             =back
55              
56             =head1 SEE ALSO
57              
58             L, L, L
59              
60             =head1 SOURCE AVAILABILITY
61              
62             This source is in Github:
63              
64             https://github.com/briandfoy/mojo-promise-role-higherorder
65              
66             =head1 AUTHOR
67              
68             brian d foy, C<< >>
69              
70             =head1 COPYRIGHT AND LICENSE
71              
72             Copyright © 2018-2021, brian d foy, All Rights Reserved.
73              
74             You may redistribute this under the terms of the Artistic License 2.0.
75              
76             =cut
77              
78             1;