| Crates.io | lazy_ref |
| lib.rs | lazy_ref |
| version | 0.4.0 |
| created_at | 2024-05-08 21:19:31.382876+00 |
| updated_at | 2024-05-09 12:45:02.936275+00 |
| description | Implements a non-blocking synchronization primitive for lazy-initialized immutable references. |
| homepage | https://github.com/andrewsonin/lazy_ref |
| repository | https://github.com/andrewsonin/lazy_ref |
| max_upload_size | |
| id | 1234553 |
| size | 15,563 |
Implements a non-blocking synchronization primitive for lazy-initialized immutable references.
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));