Crates.io | key-rwlock |
lib.rs | key-rwlock |
version | 0.1.2 |
source | src |
created_at | 2023-04-21 16:46:36.348473 |
updated_at | 2023-09-20 08:42:40.997663 |
description | Simple library for keyed asynchronous reader-writer locks |
homepage | |
repository | https://github.com/Defelo/key-rwlock |
max_upload_size | |
id | 845486 |
size | 14,096 |
Simple library for keyed asynchronous reader-writer locks.
use key_rwlock::KeyRwLock;
#[tokio::main]
async fn main() {
let lock = KeyRwLock::new();
let _foo = lock.write("foo").await;
let _bar = lock.read("bar").await;
assert!(lock.try_read("foo").await.is_err());
assert!(lock.try_write("foo").await.is_err());
assert!(lock.try_read("bar").await.is_ok());
assert!(lock.try_write("bar").await.is_err());
}