Function cros_async::select2

source ·
pub async fn select2<F1: Future + Unpin, F2: Future + Unpin>(
    f1: F1,
    f2: F2
) -> (SelectResult<F1>, SelectResult<F2>)
Expand description

Creates a combinator that runs the two given futures until one completes, returning a tuple containing the result of the finished future and the still pending future.

§Example

use cros_async::{SelectResult, select2, block_on};
use futures::future::pending;
use futures::pin_mut;

let first = async {5};
let second = async {let () = pending().await;};
pin_mut!(first);
pin_mut!(second);
match block_on(select2(first, second)) {
    (SelectResult::Finished(5), SelectResult::Pending(_second)) => (),
    _ => panic!("Select didn't return the first future"),
};