#future #rwlock #mutex #async

future-parking_lot

An "as simple as possible" Future implementation for parking_lot

7 releases

0.3.3 Nov 7, 2019
0.3.2-alpha.2 Aug 28, 2019
0.2.0-alpha.2 Aug 22, 2019
0.1.1 Jun 28, 2019

#1229 in Concurrency

Download history 60/week @ 2024-07-19 78/week @ 2024-07-26 61/week @ 2024-08-02 39/week @ 2024-08-09 33/week @ 2024-08-16 44/week @ 2024-08-23 31/week @ 2024-08-30 26/week @ 2024-09-06 28/week @ 2024-09-13 66/week @ 2024-09-20 35/week @ 2024-09-27 59/week @ 2024-10-04 70/week @ 2024-10-11 11/week @ 2024-10-18 16/week @ 2024-10-25 42/week @ 2024-11-01

156 downloads per month
Used in 2 crates

Apache-2.0/MIT

29KB
669 lines

future-parking_lot

This is an "as simple as possible" Future implementation for parking_lot. Thanks to async/await feature, now it works directly on Mutex<T> and RwLock<T>.

Example:

use std::sync::Arc;

use parking_lot::RwLock;

use future_parking_lot::rwlock::{FutureReadable, FutureWriteable};

use lazy_static::lazy_static;

lazy_static! {
    static ref LOCK: Arc<RwLock<Vec<String>>> = Arc::new(RwLock::new(Vec::new()));
}

#[tokio::main]
async fn main() -> Result<(), ()> {
    {
        let mut v = LOCK.future_write().await;
        v.push(String::from("It works!"));
    }

    let v = LOCK.future_read().await;
    assert!(v.len() == 1 && v[0] == "It works!");

    Ok(())
}

lib.rs:

future-parking_lot

A simple Future implementation for parking_lot

Dependencies

~0.8–1MB
~17K SLoC