Skip to content

Conversation

Levyks
Copy link

@Levyks Levyks commented May 24, 2025

Solves #15

I don't think we can get a proper .entry(key) function with how the shards and locks are done, but this .with_entry(key, |key, entry| {}) api should be enough for most use-cases.

Also added functions compute and compute_if_absent that are basically just wrappers around with_entry to make it easier / more convenient to use, if you think that these don't belong in here, we can remove it, as with_entry will already be enough to get the job done.

Copy link
Owner

@willothy willothy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all of your work here!

I think this is mostly good, except that the closures should probably be async so we're not forcing sync-in-async on anyone.

/// assert_eq!(map.contains_key(&"foo").await, false);
/// });
/// ```
pub async fn with_entry<R>(&self, key: K, f: impl FnOnce(K, Entry<(K, V)>) -> R) -> R {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of with_entry but I do think it should take an async function (impl Fn(A) -> impl Future<Output = R>) instead of a normal closure.

@willothy
Copy link
Owner

And I do think we could potentially get an entry API with a bit of unsafe - will look into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants