lazy_ref

Crates.iolazy_ref
lib.rslazy_ref
version0.4.0
sourcesrc
created_at2024-05-08 21:19:31.382876
updated_at2024-05-09 12:45:02.936275
descriptionImplements a non-blocking synchronization primitive for lazy-initialized immutable references.
homepagehttps://github.com/andrewsonin/lazy_ref
repositoryhttps://github.com/andrewsonin/lazy_ref
max_upload_size
id1234553
size15,563
Andrew Sonin (andrewsonin)

documentation

https://docs.rs/lazy_ref/

README

lazy_ref

Implements a non-blocking synchronization primitive for lazy-initialized immutable references.

Crates.io Documentation MIT licensed Build Status

Usage

Writing to a LazyRef from separate threads:

use rayon::prelude::*;
use lazy_ref::LazyRef;

let lazy_ref = LazyRef::new();
let thread_ids: Vec<usize> = vec![1, 2, 3];

thread_ids.par_iter()
    .for_each(
        |id| {
           let r = lazy_ref.get_or_init(|| id);
           assert!(thread_ids.contains(r));
       }
    );
let x = lazy_ref.get().unwrap();
assert!(thread_ids.contains(x));
Commit count: 7

cargo fmt