From e740de923e9d0a3952a28a7abf6e146c4da18559 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Wed, 1 Jan 2025 13:21:16 +0800 Subject: [PATCH] Add `and_try_compute_if_nobody_else` to `future::OwnedKeyEntrySelector` --- src/future/entry_selector.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/future/entry_selector.rs b/src/future/entry_selector.rs index 641a5f29..b38d1c73 100644 --- a/src/future/entry_selector.rs +++ b/src/future/entry_selector.rs @@ -238,6 +238,21 @@ where .await } + pub async fn and_try_compute_if_nobody_else( + self, + f: F, + ) -> Result, E> + where + F: FnOnce(Option>) -> Fut, + Fut: Future, E>>, + E: Send + Sync + 'static, + { + let key = Arc::new(self.owned_key); + self.cache + .try_compute_if_nobody_else_with_hash_and_fun(key, self.hash, f) + .await + } + /// Performs an upsert of an [`Entry`] by using the given closure `f`. The word /// "upsert" here means "update" or "insert". ///