NAME

Mojo::Promise::Role::Some - Fulfill when a certain number of promises are fulfilled

SYNOPSIS

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;

DESCRIPTION

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).

some( \@promises, $count )

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.

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.

SEE ALSO

Mojolicious, Mojo::Promise, Role::Tiny

http://bluebirdjs.com/docs/api/promise.some.html

SOURCE AVAILABILITY

This source is in Github:

https://github.com/briandfoy/mojo-promise-role-higherorder

AUTHOR

brian d foy, <bdfoy@cpan.org>

COPYRIGHT AND LICENSE

Copyright (c) 2018, brian d foy, All Rights Reserved.

You may redistribute this under the terms of the Artistic License 2.0.