Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async/await support? #86

Closed
rakshith-ravi opened this issue May 22, 2020 · 12 comments
Closed

Async/await support? #86

rakshith-ravi opened this issue May 22, 2020 · 12 comments

Comments

@rakshith-ravi
Copy link

Are we planning to support async/await? Would be really nice to be able to do something like:

let mut map = DashMap::new();

map.insert_async("test", "someValue").await;
map.get_async("test2").await;
@xacrimon
Copy link
Owner

I assume you mean async await for locking. V4 is releasing soon and eliminates locks which solves the problem.

@rakshith-ravi
Copy link
Author

Wait, how does that work? Wouldn't a lock be required to ensure consistency? How would it handle concurrent inserts to the same value then?

@xacrimon
Copy link
Owner

You can check out the experimental branch and the v4.0.0-rc3 version on crates.io which is the current release candidate. I spent a lot of time researching and carefully designing a lockfree hashtable.

@rakshith-ravi
Copy link
Author

rakshith-ravi commented May 22, 2020

Oh that's pretty cool! How does it work without locks though? Is there a document that I can read?

@xacrimon
Copy link
Owner

I have a technical writeup planned before the release that will be posted to the rust subreddit and that will be linked in the readme. It works by using pointer swap techniques mostly. Each entry in the table is a pointer and entries can atomically swapped with a CAS instruction. That said there are a myriad of techniques needed to make this fast and it's something you can easily write a PhD thesis on because of the complexity.

@kaimast
Copy link

kaimast commented Jun 16, 2020

Related to async/await support: Is it possible to make iter() Send, so you can iterate over a dashmap in an async function?

@xacrimon
Copy link
Owner

It is not possible to make iter send due to how locks work. At the moment I would recommend seeing if V4 works for you as it's iterators are send.

@xacrimon
Copy link
Owner

Nevermind, apparently they are not send at the moment but the v4s can theoretically impl send in the future.

@kaimast
Copy link

kaimast commented Jun 16, 2020

Yeah I am already on V4. If that's not something you are working on I might submit a pull request at some point.

@xacrimon
Copy link
Owner

It looks to be safe to implement. All that need to be done is unsafe impl send and sync if both K and V are send and sync respectively.

@xacrimon
Copy link
Owner

A PR would be appreciated. Make sure to merge into the experimental branch.

@kaimast
Copy link

kaimast commented Jul 2, 2020

I started looking at this but noticed the experimental branch is undergoing some changes right now. I will try to take a look again in a few days.

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

No branches or pull requests

3 participants