any<E, F, A> static method
Races multiple continuations, returning the first successful value.
Executes all continuations in list and returns the first one that succeeds.
If all fail, their errors are collected into a List. A crash ends the race,
like a success. The execution behavior depends on the provided policy:
- SequenceOkPolicy: Tries continuations one by one in order until one succeeds or crashes.
- RunAllOkPolicy: Runs all in parallel; if multiple succeed, combines their values using the policy's combine function; otherwise returns the success or collects all errors if all fail. Errors are collected in completion order, and crashes are reported as a CollectedCrash.
- QuitFastOkPolicy: Runs all in parallel, returns immediately on first success or crash.
SequenceOkPolicy and QuitFastOkPolicy keep list order. An empty
list fails with [].
list: List of continuations to race.policy: Execution policy determining how continuations are run.
Implementation
static Cont<E, List<F>, A> any<E, F, A>(
List<Cont<E, F, A>> list, {
required OkPolicy<A> policy,
}) {
switch (policy) {
case SequenceOkPolicy<A>():
return _anySequence(list);
case QuitFastOkPolicy<A>():
return _quitFastAny(list);
case RunAllOkPolicy<A>(
combine: final combine,
shouldFavorCrash: final shouldFavorCrash,
):
return _whenAllAny(list, combine, shouldFavorCrash);
}
}