[][src]Function futures_either::try_either_fair

pub fn try_either_fair<OL, OR, E, L, R>(
    left: L,
    right: R
) -> TryEitherFair<L, R>

Notable traits for TryEitherFair<L, R>

impl<OL, OR, E, L, R> Future for TryEitherFair<L, R> where
    L: Future<Output = Result<OL, E>>,
    R: Future<Output = Result<OR, E>>, 
type Output = Result<Either<OL, OR>, E>;
where
    L: Future<Output = Result<OL, E>>,
    R: Future<Output = Result<OR, E>>, 

Returns a future polling two futures and returning a result with the ouput or error returned by the first one to complete.

The returned future will choose which future to poll first randomly, each time it is being polled; for an "unfair" alternative, see try_either().

Example

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

let out = try_either_fair(
    async { Ok(42) },
    async { Result::<bool, bool>::Err(false) },
).await;
assert!(out == Ok(Either::Left(42)) || out == Err(false));

let out = try_either_fair(
    future::pending::<Result<bool, i32>>(),
    async { Result::<i32, i32>::Err(42) },
).await;
assert_eq!(out, Err(42));