This is a Rust library for awaiting multiple futures and getting the value of the first one that completes.
You can use it with safina
or any async runtime.
forbid(unsafe_code)
std
rust
use safina_async_test::async_test;
use safina_select::{select_ab, OptionAB};
let conn = match select_ab(make_new(addr.clone()), get_from_pool(addr.clone())).await {
OptionAB::A(result) => result?,
OptionAB::B(result) => result?,
};
// When both futures return the same type, you can use `take`:
let conn = select_ab(make_new(addr.clone()), get_from_pool(addr.clone())).await.take()?;
rust
use safina_async_test::async_test;
use safina_select::{select_ab, OptionAB};
safina_timer::start_timer_thread();
let data = match select_ab(read_data(), safina_timer::sleep_until(deadline)).await {
OptionAB::A(result) => Ok(result?),
OptionAB::B(()) => Err("timeout"),
};
https://docs.rs/safina-select
unsafe
unsafe
codeCargo.toml
and bump version number../release.sh
sleep_ab
sleep_abc
, sleep_abcd
, and sleep_abcde
License: Apache-2.0