async-drop 0.1.2

simple async drop
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 5 items with examples
  • Size
  • Source code size: 10.92 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 25s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • fpena2/async-drop
    1 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fpena2

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

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