Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fpena2/async-drop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

14 Commits

Repository files navigation

Async Drop

Inspired by async-dropper

Adjustments

  • Removed async_trait crate dependency
  • Types don't have to implement Default
  • Dropper's drop will wait until async_drop completes
  • Only compatible with the tokio runtime (for now)

Usage

{ Box::pin(async { tokio::time::sleep(Duration::from_secs(3)).await; println!("dropped"); Ok(()) }) } } #[tokio::main] async fn main() { { let _thing = Dropper::new(Thing); println!("dropping..."); } // `_thing` is dropped here, but before that happens `async_drop()` will run to completion } ">struct Thing;

impl AsyncDrop for Thing {
fn async_drop(&mut self) -> AsyncDropFuture<'_> {
Box::pin(async {
tokio::time::sleep(Duration::from_secs(3)).await;
println!("dropped");
Ok(())
})
}
}

#[tokio::main]
async fn main() {
{
let _thing = Dropper::new(Thing);
println!("dropping...");
} // `_thing` is dropped here, but before that happens `async_drop()` will run to completion
}

Examples

See test and example directories

About

simple async drop for rust types

Resources

Readme

Stars

Watchers

Forks

Contributors

Languages