Closed
Description
Feature gate: #![feature(once_wait)]
This is a tracking issue for adding a blocking .wait()
method on Once
and OnceLock
, to allow other threads to synchronize on their completion. This will provide the same interface as once_cell
's OnceCell::wait
.
Public API
impl Once {
/// Block the current thread until the `Once` has been initialized.
fn wait(&self);
/// Block the current thread until the `Once` has been initialized, ignoring poisoning.
fn wait_force(&self);
}
impl OnceLock {
/// Block the current thread until the value is set, then return it.
fn wait(&self) -> &T;
}
Steps / History
- ACP: Add
OnceLock::wait
libs-team#405 - Implementation: std: implement the
once_wait
feature #127567 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Async API (proposed in the ACP): naming, how it works, interaction with other synchronization primitives since e.g.
Mutex
does not have async methods. This would probably get its own feature gate.