async-safe-defer 0.2.0

Runtime-independent LIFO cleanup scopes for synchronous and asynchronous Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use async_safe_defer::async_scope;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), &'static str> {
    async_scope!(scope, {
        scope.defer(|| async {
            println!("disconnect");
        });
        scope.defer(|| async {
            println!("flush");
        });

        println!("work");
        Ok(())
    })
    .await
}