[][src]Function futures_either::either

pub fn either<L, R>(left: L, right: R) -> Either<L, R>

Notable traits for Either<L, R>

impl<L, R> Future for Either<L, R> where
    L: Future,
    R: Future
type Output = Either<L::Output, R::Output>;
where
    L: Future,
    R: Future

Returns a future polling two futures and returning the output of the first one to complete.

The returned future will always poll left first; for a "fair" alternative, see either_fair().

Example

use futures_lite::future;
use futures_either::{either, Either};

let out = either(
    async { 42 },
    async { false },
).await;
assert_eq!(out, Either::Left(42));

let out = either(
    future::pending::<bool>(),
    async { 42 },
).await;
assert_eq!(out, Either::Right(42));