Skip to content

await-protected API #343

Description

@sukhmel

I happened to create deadlocks accidentally by holding a reference into the DashMap across awaits, and came to think that maybe it might be possible to make an API that disallowed such use even by accident?

It looks like one way to do that is to bar all the work performed on the returned value behind a function, something like this:

pub fn process<Q, R, F: FnOnce(&T) -> R>(&'a self, key: &Q, f: F) -> R {
    f(self.get(key))
}

pub fn process_mut<Q, R, F: FnOnce(&mut T) -> R>(&'a self, key: &Q, f: F) -> R {
    f(self.get_mut(key)) 
}

Is there a better way to do that? Maybe there's some way to opt-in to non-awaitable code without changes to DashMap by wrapping return value into something clever?

Is there a need for such API?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions