-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Feature Request: Get or Insert Future #15
Comments
Thanks for your suggestion. I think this would be a good feature to add. I will work on it once I finish working on another feature (#12). Which Moka |
Futures- thanks ^^ |
Hi @Dessix I created a topic branch and added the following methods to the future cache: async fn get_or_insert_with(&self, key: K, init: impl Future<Output = V>) -> V
async fn get_or_try_insert_with<F>(&self, key: K, init: F) -> Result<V, Arc<Box<dyn Error>>>
where
F: Future<Output = Result<V, Box<dyn Error>>>
Please check the unit tests out as they will show you how to use them (test1 and test2). Let me know what you think. |
Finished developing and #20 has been merged into the master branch. I am going to release Moka v0.5.0 with this feature in a day or so. |
Published Moka v0.5.0 to crates.io. |
The ability to get-or-insert atomically would be nice for preventing multiple requests for the same resource from being created to populate the cache. Otherwise, there's a race condition between get and insert where another task could attempt to get as well, and also see an empty record to populate.
The text was updated successfully, but these errors were encountered: