Skip to content

Commit

Permalink
Clarify that SyncOnceCell::set blocks.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rkjnsn committed Feb 28, 2021
1 parent 573a697 commit 2616960
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/std/src/lazy.rs
Expand Up @@ -177,7 +177,10 @@ impl<T> SyncOnceCell<T> {

/// Sets the contents of this cell to `value`.
///
/// Returns `Ok(())` if the cell's value was updated.
/// May block if another thread is currently attempting to initialize the cell. The cell is
/// guaranteed to contain a value when set returns, though not necessarily the one provided.
///
/// Returns `Ok(())` if the cell's value was set by this call.
///
/// # Examples
///
Expand Down

0 comments on commit 2616960

Please sign in to comment.