Crates.io | futures-finally |
lib.rs | futures-finally |
version | 0.1.0-alpha.2 |
source | src |
created_at | 2024-07-01 00:56:44.539797 |
updated_at | 2024-07-01 04:05:14.055427 |
description | A utility that executes a future after the completion of a future or stream regardless of the value or outcome. |
homepage | |
repository | https://github.com/dariusc93/futures-finally |
max_upload_size | |
id | 1288275 |
size | 25,271 |
A small utility that provides two functions to executes a future after the completion of a future or stream.
I written this small library due to wanting to execute specific asynchronous code after the completion of a future or stream. This could be awaiting another future, sending data through a channel, etc.
use futures_finally::future::ThenFinallyFutureExt;
fn main() {
futures::executor::block_on(async move {
let mut val = 0;
futures::future::ready(())
.then_finally(|| async {
val = 1;
})
.await;
assert_eq!(val, 1);
});
}
use futures::StreamExt;
use futures_finally::stream::FinallyStreamExt;
fn main() {
futures::executor::block_on(async move {
let mut val = 0;
let st = futures::stream::once(async { 0 }).finally(|| async {
val = 1;
});
futures::pin_mut!(st);
while let Some(v) = st.next().await {
assert_eq!(v, 0);
}
assert_eq!(val, 1);
});
}
The minimum supported rust version is 1.75, which can be changed in the future. There is no guarantee that this library will work on older versions of rust.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.