Crate key_rwlock

Source
Expand description

check test codecov Version dependency status

§key-rwlock

Simple library for keyed asynchronous reader-writer locks.

§Example

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

Structs§

KeyRwLock
An async reader-writer lock, that locks based on a key, while allowing other keys to lock independently. Based on a HashMap of RwLocks.