Skip to content

Tracking Issue for once_wait #127527

Closed

Description

@tgross35

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

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.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    C-tracking-issue
    T-libs-api
    on Jul 9, 2024
  2. added a commit that references this issue on Jul 31, 2024
  3. added a commit that references this issue on Jul 31, 2024
  4. added a commit that references this issue on Aug 1, 2024
  5. PhilipDaniels commented on Nov 18, 2024

    @PhilipDaniels
    Contributor

    This would be very useful, frankly I was surprised when I ran into the problem of get being non-blocking! Pretty-please can this be moved forward to stabilisation?

  6. orlp commented on Jan 7, 2025

    @orlp
    Contributor

    I don't know about wait_force, but I think wait is clear and uncontroversial enough to stabilize?

  7. tgross35 commented on Jan 7, 2025

    @tgross35
    MemberAuthor

    wait_force does mirror call_once_force so it makes sense in that regard. That being said, I think the usecases for wait_force are pretty few and far between outside of implementing OnceLock, and a better solution in the long term will be to use the sync::nonpoison types. So, unless there is a convincing usecase (cc author @joboet), maybe it is better to just leave wait_force internal? (quick usage search doesn't show anything, not entirely surprising for less common nightly API though).

    Requesting libs-api to consider stabilizing at least Once::wait and OnceLock::wait, possibly deferring Once::force_wait.

    @rustbot label +I-libs-api-nominated

  8. added
    I-libs-api-nominated
    on Jan 7, 2025
  9. m-ou-se commented on Jan 14, 2025

    @m-ou-se
    Member

    @rfcbot merge

  10. rfcbot commented on Jan 14, 2025

    @rfcbot

    Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

    No concerns currently listed.

    Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

    See this document for info about what commands tagged team members can give me.

  11. added
    proposed-final-comment-period
    disposition-merge
    on Jan 14, 2025
  12. tgross35 commented on Jan 14, 2025

    @tgross35
    MemberAuthor

    ^ just to clarify what is in FCP, the meeting notes say

    No reason to not also include wait_force

  13. added
    final-comment-period
    and removed
    proposed-final-comment-period
    on Jan 21, 2025
  14. rfcbot commented on Jan 21, 2025

    @rfcbot

    🔔 This is now entering its final comment period, as per the review above. 🔔

  15. removed
    I-libs-api-nominated
    on Jan 21, 2025
  16. added
    finished-final-comment-period
    to-announce
    and removed
    final-comment-period
    on Jan 31, 2025
  17. rfcbot commented on Jan 31, 2025

    @rfcbot

    The final comment period, with a disposition to merge, as per the review above, is now complete.

    As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

    This will be merged soon.

  18. added a commit that references this issue on Feb 1, 2025
  19. added a commit that references this issue on Feb 1, 2025
  20. removed
    to-announce
    on Feb 7, 2025
  21. added a commit that references this issue on Mar 11, 2025
  22. added this to the 1.86.0 milestone on Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueT-libs-apidisposition-mergefinished-final-comment-period

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions