Module async::combinator
async: combinators (join, select, timeout, map, and_then)
Futures built from other futures, as in Rust's futures::future and tokio's join!/select!/timeout. Each takes its children by value (move them in before the first poll: futures are pinned once polled) and owns them: it polls them, and drops the ones it abandons — select drops the loser, timeout drops the inner future when time runs out, and drop() of a combinator drops every child still running.
Rust infers a combinator's output from its children; SafeC generics can't name "the T of F's Poll<T>", so the output types are type parameters too, written in the declaration and inferred from it:
struct Join2<struct Sleep, struct Fetch, Unit, int> j =
join2(Sleep::new(50LL), Fetch::new());
AWAIT_INTO(1, self.both, self.j); // self.both: struct Both<Unit, int>
struct Timeout<struct Fetch, int> t = timeout(Fetch::new(), 100LL);
AWAIT_INTO(2, self.res, self.t); // self.res: ?int (null = timed out)
Nothing here allocates. JoinAll and SelectAny take caller-provided slices of futures (and of output slots), up to 64 futures.
Structs
| Both | Both outputs of a Join2 (Rust's (A, B)). |
| Either | Which future a Select2 picked, and its output (Rust's Either; the other field is unset). It owns that output when its type owns something. |
| Picked | One output of a SelectAny, and whose it is. |
| Join2 | Polls both until both are Ready (tokio::join!). Output: Both<TA, TB>. |
| Join3 | Three at once. Output: Both<TA, Both<TB, TC>> -- (a, (b, c)). |
| JoinAll | Polls every future in 'futs' until all are Ready, storing future i's output in outs[i] (futures::future::join_all, without the heap). Output: how many (= futs.len). At most 64 futures. |
| Select2 | The first of two to be Ready wins; the other is dropped (tokio::select! with two branches, polled in order). Output: Either<TA, TB>. |
| SelectAny | The first in 'futs' to be Ready wins (lowest index on a tie); the rest are dropped (futures::future::select_all). Output: Picked<T>. |
| Timeout | 'inner', unless 'ms' milliseconds pass first: then 'inner' is dropped (tokio::time::timeout). Output: ?T, null on timeout. Needs timers. |
| MapFut | 'inner''s output passed through f (FutureExt::map). Output: U. |
| AndThen | Runs 'first', then the future f makes from its output (and_then / .then). Output: U, the second future's. |
Functions
| join2 | |
| join3 | |
| join_all | |
| select2 | |
| select_any | |
| timeout | |
| map_fut | |
| and_then |