Skip to content

Commit

Permalink
Add blocking backend
Browse files Browse the repository at this point in the history
  • Loading branch information
alpha-tango-kilo committed Nov 11, 2023
1 parent 463d532 commit b0324f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Each listed backend comes with a corresponding feature `backend-<name>`.
To use a non-default backend, set `default-features = false` and enable the corresponding `backend-<name>` 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
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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
///
Expand Down

0 comments on commit b0324f8

Please sign in to comment.