Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rossmacarthur/fmutex
Provides mutual exclusion on a file using flock(2)
https://github.com/rossmacarthur/fmutex
Last synced: 9 days ago
JSON representation
Provides mutual exclusion on a file using flock(2)
- Host: GitHub
- URL: https://github.com/rossmacarthur/fmutex
- Owner: rossmacarthur
- License: apache-2.0
- Created: 2022-02-09T10:27:40.000Z (almost 3 years ago)
- Default Branch: trunk
- Last Pushed: 2022-02-09T10:28:04.000Z (almost 3 years ago)
- Last Synced: 2024-09-14T14:48:24.825Z (about 2 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# fmutex
[![Crates.io Version](https://img.shields.io/crates/v/fmutex.svg)](https://crates.io/crates/fmutex)
[![Docs.rs Latest](https://img.shields.io/badge/docs.rs-latest-blue.svg)](https://docs.rs/fmutex)Provides mutual exclusion on a file using
[`flock(2)`](https://man7.org/linux/man-pages/man2/flock.2.html).## Usage
### `lock()`
```rust
{
let _guard = fmutex::lock(path)?;// do mutually exclusive stuff here
} // <-- `_guard` dropped here and the lock is released
```### `try_lock()`
```rust
match fmutex::try_lock(path)? {
Some(_guard) => {// do mutually exclusive stuff here
} // <-- `_guard` dropped here and the lock is released
None => {
eprintln!("warn: the lock could not be acquired!");
}
}
```## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.