The set of tasks to check for any resolution.
A Task which is either Resolved
with the value of the
first task to resolve, or Rejected
with the rejection reasons
for all the tasks passed in in an AggregateRejection
. Note that
the order of the rejection reasons is not guaranteed.
Given an array of tasks, return a new Task
which resolves once
any of the tasks resolves successfully, or which rejects once all the
tasks have rejected.
When any item resolves:
import { any, timer } from 'true-myth/task';
let anyTask = any([
timer(20),
timer(10),
timer(30),
]);
let result = await anyTask;
console.log(result.toString()); // Ok(10);
When all items reject:
import Task, { timer } from 'true-myth/task';
let anyTask = any([
timer(20).andThen((time) => Task.reject(`${time}ms`)),
timer(10).andThen((time) => Task.reject(`${time}ms`)),
timer(30).andThen((time) => Task.reject(`${time}ms`)),
]);
let result = await anyTask;
console.log(result.toString()); // Err(AggregateRejection: `Task.race`: 10ms,20ms,30ms)
(Note that the order in the resulting AggregateRejection
is not guaranteed
to be stable!)
The set of tasks to check for any resolution.
A Task which is either Resolved
with the value of the
first task to resolve, or Rejected
with the rejection reasons
for all the tasks passed in in an AggregateRejection
. Note that
the order of the rejection reasons is not guaranteed.
Given an array of tasks, return a new
Task
which resolves once any of the tasks resolves successfully, or which rejects once all the tasks have rejected.Examples
When any item resolves:
When all items reject:
(Note that the order in the resulting
AggregateRejection
is not guaranteed to be stable!)