diff --git a/CHANGELOG.md b/CHANGELOG.md index 2126a57..e5c0ae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,19 +2,23 @@ ## Unreleased +- + +## 1.12.0 + - Add `OnceCell::wait`, a blocking variant of `get`. -## 1.11 +## 1.11.0 - Add `OnceCell::with_value` to create initialized `OnceCell` in `const` context. - Improve `Clone` implementation for `OnceCell`. - Rewrite `parking_lot` version on top of `parking_lot_core`, for even smaller cells! -## 1.10 +## 1.10.0 - upgrade `parking_lot` to `0.12.0` (note that this bumps MSRV with `parking_lot` feature enabled to `1.49.0`). -## 1.9 +## 1.9.0 - Added an `atomic-polyfill` optional dependency to compile `race` on platforms without atomics diff --git a/Cargo.toml b/Cargo.toml index daba1e8..5c77dfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "once_cell" -version = "1.12.0-pre.1" +version = "1.12.0" authors = ["Aleksey Kladov "] license = "MIT OR Apache-2.0" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index d716ea0..0b23a36 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -875,7 +875,26 @@ pub mod sync { } } - /// Blocks until the value is set by another thread. + /// Gets the reference to the underlying value, blocking the current + /// thread until it is set. + /// + /// ``` + /// use once_cell::sync::OnceCell; + /// + /// let mut cell = std::sync::Arc::new(OnceCell::new()); + /// let t = std::thread::spawn({ + /// let cell = std::sync::Arc::clone(&cell); + /// move || cell.set(92).unwrap() + /// }); + /// + /// // Returns immediately, but might return None. + /// let _value_or_none = cell.get(); + /// + /// // Will return 92, but might block until the other thread does `.set`. + /// let value: &u32 = cell.wait(); + /// assert_eq!(*value, 92); + /// t.join().unwrap();; + /// ``` pub fn wait(&self) -> &T { if !self.0.is_initialized() { self.0.wait()