[−][src]Function futures_either::try_either
pub fn try_either<OL, OR, E, L, R>(left: L, right: R) -> TryEither<L, R>ⓘ 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 output or error returned by the first one to complete.
The returned future will always poll left
first; for a "fair" alternative, see
try_either_fair()
.
Example
use futures_lite::future; use futures_either::{try_either, Either}; let out = try_either( async { Ok(42) }, async { Result::<bool, bool>::Err(false) }, ).await; assert_eq!(out, Ok(Either::Left(42))); let out = try_either( future::pending::<Result<bool, i32>>(), async { Result::<i32, i32>::Err(42) }, ).await; assert_eq!(out, Err(42));