Mojo::Promise::Role::Some - Fulfill when a certain number of promises are fulfilled
use Mojo::Promise; use Mojo::Util qw(dumper); my @promises = map { Mojo::Promise->new } 0 .. 5; my $some_promise = Mojo::Promise ->with_roles( '+Some' ) ->some( \@promises, $count_to_fulfill ); $some_promise->then( sub { say dumper( @_ ) } sub { say "Failed!" } ); $some_promise->wait;
Make a new promise that fulfills with a certain number of its promises fulfill. Fire off several tasks and fulfill when a minimum number of them work out.
This should be the Perl expression of the same idea in bluebirdjs (http://bluebirdjs.com/docs/api/promise.some.html).
Takes a lists of promises (or thenables) and returns another promise that fulfills when $count promises fulfill. The result is list of array references for the arguments for the fulfilled promises in the order that they were fulfilled.
$count
If less than $count promises fulfill then the some promise rejects. The result is list of array references for the arguments for the rejected promises in the order that they were rejected. The number of elements in that list should be the PROMISES - COUNT + 1 since the extra reject is the response that makes it impossible to get to COUNT fulfills.
If you pass no promises, the some promise fulfills if you specify $count = 0 and rejects otherwise.
$count = 0
Mojolicious, Mojo::Promise, Role::Tiny
http://bluebirdjs.com/docs/api/promise.some.html
This source is in Github:
https://github.com/briandfoy/mojo-promise-any-none-some
brian d foy, <bdfoy@cpan.org>
<bdfoy@cpan.org>
Copyright (c) 2018, brian d foy, All Rights Reserved.
You may redistribute this under the terms of the Artistic License 2.0.
To install Mojo::Promise::Role::HigherOrder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Promise::Role::HigherOrder
CPAN shell
perl -MCPAN -e shell install Mojo::Promise::Role::HigherOrder
For more information on module installation, please visit the detailed CPAN module installation guide.