Skip to content

Commit

Permalink
Merge #179
Browse files Browse the repository at this point in the history
179: publish v1.12.0 r=matklad a=matklad

closes #102

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
  • Loading branch information
bors[bot] and matklad committed May 23, 2022
2 parents 62b4579 + 9f43e04 commit 9879c77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "once_cell"
version = "1.12.0-pre.1"
version = "1.12.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2018"
Expand Down
21 changes: 20 additions & 1 deletion src/lib.rs
Expand Up @@ -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()
Expand Down

0 comments on commit 9879c77

Please sign in to comment.