diff --git a/Cargo.toml b/Cargo.toml index d20a97e..8a323a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ repository = "https://codeberg.org/alpha-tango-kilo/close_already" [features] default = ["backend-threadpool"] backend-async-std = ["dep:async-std"] +backend-blocking = ["dep:blocking"] backend-rayon = ["dep:rayon"] backend-smol = ["dep:smol"] backend-threadpool = ["dep:threadpool"] @@ -22,6 +23,7 @@ backend-tokio = ["dep:tokio"] mutually_exclusive_features = "0.0.3" # Backends async-std = { version = "1", optional = true } +blocking = { version = "1.2", optional = true } rayon = { version = "1", optional = true } smol = { version = "1", optional = true } tokio = { version = "1", features = ["rt", "fs"], optional = true } diff --git a/README.md b/README.md index 607d4de..ae41d02 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,9 @@ Each listed backend comes with a corresponding feature `backend-`. To use a non-default backend, set `default-features = false` and enable the corresponding `backend-` feature Supported backends: -* [`threadpool`](https://lib.rs/crates/threadpool) - default, creates and uses its own OS-thread threadpool -* [`rayon`](https://lib.rs/crates/rayon) - uses rayon's global threadpool +* [`threadpool`](https://lib.rs/crates/threadpool) - default, creates and uses its own OS-thread thread pool +* [`blocking`](https://lib.rs/crates/blocking) - uses `blocking`'s thread pool +* [`rayon`](https://lib.rs/crates/rayon) - uses `rayon`'s global thread pool * [`async-std`](https://lib.rs/crates/async-std) - uses `async-std`'s global executor. `async_std`'s `File` is supported * [`smol`](https://lib.rs/crates/smol) - uses `smol`'s global executor. `smol`'s `File` is supported * [`tokio`](https://lib.rs/crates/tokio) - uses `tokio`'s global executor. `tokio`'s `File` is supported. Enables the `rt` and `fs` features diff --git a/src/lib.rs b/src/lib.rs index 7d1cb7c..a897fb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ use std::{ mutually_exclusive_features::exactly_one_of! { "backend-async-std", + "backend-blocking", "backend-rayon", "backend-smol", "backend-threadpool", @@ -80,6 +81,18 @@ mod windows { closer_pool.execute(move || drop(handle)); } + /// Submits the file handle as a `blocking` task to handle its + /// closure + /// + /// Note: on non-Windows targets, nothing is done, the handle is just + /// dropped normally + #[cfg(feature = "backend-blocking")] + fn drop(&mut self) { + // SAFETY: we're in Drop, so self.0 won't be accessed again + let handle = unsafe { self.get_handle() }; + blocking::unblock(move || drop(handle)).detach(); + } + /// Submits the file handle to `rayon`'s thread pool to handle its /// closure ///