Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fawdlstty/async-sema-rs
Async semaphore library
https://github.com/fawdlstty/async-sema-rs
Last synced: 3 months ago
JSON representation
Async semaphore library
- Host: GitHub
- URL: https://github.com/fawdlstty/async-sema-rs
- Owner: fawdlstty
- License: mit
- Created: 2024-07-19T15:50:29.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-25T16:15:31.000Z (6 months ago)
- Last Synced: 2024-10-07T07:56:49.330Z (3 months ago)
- Language: Rust
- Homepage: https://crates.io/crates/async-sema
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# async-sema-rs
![version](https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2Ffawdlstty%2Fasync-sema-rs%2Fmain%2FCargo.toml&query=package.version&label=version)
![status](https://img.shields.io/github/actions/workflow/status/fawdlstty/async-sema-rs/rust.yml)Async semaphore library
## Manual
Install: Run `cargo add async-sema` in the project directory
## example
```rust
use async_sema::Semaphore;let s = Semaphore::new(2);
// async acquire
s.acquire().await;
s.batch_acquire(1).await;// instant acquire
let a = s.try_acquire().unwrap();assert!(s.try_acquire().is_none());
s.add_permits(1);
assert!(s.try_acquire().is_some());
```