6 releases
| 0.1.5 | Oct 27, 2024 |
|---|---|
| 0.1.4 | Feb 25, 2022 |
| 0.1.3 | Mar 27, 2021 |
| 0.1.2 | Dec 24, 2020 |
#2542 in Asynchronous
337 downloads per month
60KB
1.5K
SLoC
ARCHIVED ARCHIVED ARCHIVED
This crate is archived and will not be updated.
The code is now at
safina::select in the
safina crate.
safina-select
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.
Features
forbid(unsafe_code)- Depends only on
std - Good test coverage (96%)
- Works with
safina-executoror any async executor
Limitations
- Can await 2-5 futures. Nest them if you need more.
Examples
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()?;
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"),
};
Documentation
TO DO - Alternatives
tokio::select- very popular
- Fast
- internally incredibly complicated
- full of
unsafe
futures::select- very popular
- proc macro, very complicated
- contains a little
unsafecode
Changelog
- V0.1.4 - Update docs.
- v0.1.3 - Rename
OptionABtoOptionAb, etc. - v0.1.2 - Satisfy pedantic clippy
- v0.1.1 - Add badges to readme. Rename
safinapackage tosafina-executor. - v0.1.0 - First published version
TO DO
Release Process
- Edit
Cargo.tomland bump version number. - Run
./release.sh