allof
ErrorsCollection

allof

Synthesised documentation from type/Promise

From type/Promise

See Original text in context

method allof(Promise:U: *@promises --> Promise:D)

Returns a new promise that will be kept when all the promises passed as arguments are kept or broken. The result of the individual Promises is not reflected in the result of the returned promise: it simply indicates that all the promises have been completed in some way. If the results of the individual promises are important then they should be inspected after the allof promise is kept.

In the following requesting the result of a broken promise will cause the original Exception to be thrown. (You may need to run it several times to see the exception.)

my @promises;
for 1..5 -> $t {
    push @promisesstart {
        sleep $t;
    };
}
my $all-done = Promise.allof(@promises);
await $all-done;
@promises>>.result;
say "Promises kept so we get to live another day!";