Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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());
```