Skip to content

Commit 9a86a72

Browse files
author
Joshua Nelson
authored
Rollup merge of #82645 - rkjnsn:patch-3, r=Mark-Simulacrum
Clarify that SyncOnceCell::set blocks. Reading the discussion of this feature, I gained the mistaken impression that neither `set` nor `get` blocked, and thus calling `get` immediately after `set` was not guaranteed to succeed. It turns out that `set` *does* block, guaranteeing that the cell contains a value once `set` returns. This change updates the documentation to state that explicitly. Happy to adjust the wording as desired.
2 parents 6873831 + 2616960 commit 9a86a72

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

library/std/src/lazy.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ impl<T> SyncOnceCell<T> {
177177

178178
/// Sets the contents of this cell to `value`.
179179
///
180-
/// Returns `Ok(())` if the cell's value was updated.
180+
/// May block if another thread is currently attempting to initialize the cell. The cell is
181+
/// guaranteed to contain a value when set returns, though not necessarily the one provided.
182+
///
183+
/// Returns `Ok(())` if the cell's value was set by this call.
181184
///
182185
/// # Examples
183186
///

0 commit comments

Comments
 (0)