Skip to content

Commit

Permalink
Merge pull request #476 from moka-rs/followup-adding-and_try_compute_…
Browse files Browse the repository at this point in the history
…if_nobody_else

Add `and_try_compute_if_nobody_else` to `future::OwnedKeyEntrySelector`
  • Loading branch information
tatsuya6502 authored Jan 1, 2025
2 parents ba09737 + e740de9 commit cf7a279
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/future/entry_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ where
.await
}

pub async fn and_try_compute_if_nobody_else<F, Fut, E>(
self,
f: F,
) -> Result<compute::CompResult<K, V>, E>
where
F: FnOnce(Option<Entry<K, V>>) -> Fut,
Fut: Future<Output = Result<compute::Op<V>, 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".
///
Expand Down

0 comments on commit cf7a279

Please sign in to comment.