From 9741c90f9f8b14a7d78d7629a29a281602d5f2b9 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sun, 3 Aug 2025 09:42:30 +0200 Subject: [PATCH] sync: document cancel safety on `SetOnce::wait` (#7506) --- tokio/src/sync/set_once.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tokio/src/sync/set_once.rs b/tokio/src/sync/set_once.rs index b8615ae87..e4adbf593 100644 --- a/tokio/src/sync/set_once.rs +++ b/tokio/src/sync/set_once.rs @@ -338,17 +338,14 @@ impl SetOnce { } } - /// Waits until set is called. The future returned will keep blocking until - /// the `SetOnce` is initialized. + /// Waits until the value is set. /// /// If the `SetOnce` is already initialized, it will return the value /// immediately. /// - /// # Note + /// # Cancel safety /// - /// This will keep waiting until the `SetOnce` is initialized, so it - /// should be used with care to avoid blocking the current task - /// indefinitely. + /// This method is cancel safe. pub async fn wait(&self) -> &T { loop { if let Some(val) = self.get() {