Crates.io | safina-select |
lib.rs | safina-select |
version | 0.1.5 |
source | src |
created_at | 2020-12-12 04:37:53.983134 |
updated_at | 2024-10-27 23:44:40.234184 |
description | Safe async select function, for awaiting multiple futures - ARCHIVED: Code moved to `safina` crate. |
homepage | |
repository | https://gitlab.com/leonhard-llc/safina-rs |
max_upload_size | |
id | 322074 |
size | 59,805 |
This crate is archived and will not be updated.
The code is now at
safina::select
in the
safina
crate.
This is a Rust library for awaiting multiple futures and getting the value of the first one that completes.
It is part of safina
, a safe async runtime.
forbid(unsafe_code)
std
safina-executor
or any async executoruse 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()?;
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"),
};
tokio::select
unsafe
futures::select
unsafe
codeOptionAB
to OptionAb
, etc.safina
package to safina-executor
.Cargo.toml
and bump version number../release.sh