#semaphore #async #lock

async-sema

Async semaphore library

5 releases

0.1.4 Jul 25, 2024
0.1.3 Jul 25, 2024
0.1.2 Jul 22, 2024
0.1.1 Jul 20, 2024
0.1.0 Jul 19, 2024

#760 in Concurrency


Used in channel

MIT license

7KB
79 lines

async-sema-rs

version status

Async semaphore library

Manual

Install: Run cargo add async-sema in the project directory

example

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

Dependencies

~350KB