[][src]Crate async_mutex

An async mutex.

Examples

use async_mutex::Mutex;
use smol::Task;
use std::sync::Arc;

let m = Arc::new(Mutex::new(0));
let mut tasks = vec![];

for _ in 0..10 {
    let m = m.clone();
    tasks.push(Task::spawn(async move {
        *m.lock().await += 1;
    }));
}

for t in tasks {
    t.await;
}
assert_eq!(*m.lock().await, 10);

Structs

Mutex

An async mutex.

MutexGuard

A guard that releases the mutex when dropped.