pub async fn select<A, B, F1, F2>(f1: F1, f2: F2) -> Either<A, B> ⓘExpand description
Run two futures, taking whichever finishes first and canceling the other.
Notice that this is built on futures::future::select, which has the
same overall semantics but does not drop the slower future. The idea there
is that you can work with the first result and then later also continue
waiting for the second future.
We drop the slower future for the sake of simplicity in the examples: no need to deal with the tuple and intentionally ignore the second future this way!
Note that this only works as “simply” as it does because:
- It takes ownership of the futures.
- It internally pins the futures.
- It throws away (rather than returning) the unused future (which is why it can get away with pinning them).