From ea031461c5f56b3ae3996e533ffba0d28e2521cf Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Mon, 1 Jul 2024 15:17:37 -0400 Subject: [PATCH] Simplify `OnceMap::wait_blocking` (#4704) ## Summary De-duplicate by calling directly into the async version. --- crates/once-map/src/lib.rs | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/crates/once-map/src/lib.rs b/crates/once-map/src/lib.rs index 7c3ed5b7d..1e64885b9 100644 --- a/crates/once-map/src/lib.rs +++ b/crates/once-map/src/lib.rs @@ -77,30 +77,7 @@ impl OnceMap { /// /// Will hang if [`OnceMap::done`] isn't called for this key. pub fn wait_blocking(&self, key: &K) -> Option { - let notify = { - let entry = self.items.get(key)?; - match entry.value() { - Value::Filled(value) => return Some(value.clone()), - Value::Waiting(notify) => notify.clone(), - } - }; - - // Register the waiter for calls to `notify_waiters`. - let notification = pin!(notify.notified()); - - // Make sure the value wasn't inserted in-between us checking the map and registering the waiter. - if let Value::Filled(value) = self.items.get(key).expect("map is append-only").value() { - return Some(value.clone()); - }; - - // Wait until the value is inserted. - futures::executor::block_on(notification); - - let entry = self.items.get(key).expect("map is append-only"); - match entry.value() { - Value::Filled(value) => Some(value.clone()), - Value::Waiting(_) => unreachable!("notify was called"), - } + futures::executor::block_on(self.wait(key)) } /// Return the result of a previous job, if any.