anp / moxie

lightweight platform-agnostic tools for declarative UI
https://moxie.rs
Apache License 2.0
828 stars 27 forks source link

SharedSendCache should allow `cache_with` callers to block on other callers to the same key #170

Open anp opened 4 years ago

anp commented 4 years ago

We don't hold the lock around the cache while initializing stored values so that the cache can be called re-entrantly. In the single-threaded case this has obvious behavior. In the multi-threaded case it's quite likely for multiple clients of a query to simultaneously find the cache needs to be populated and to run the query multiple times between them.

To prevent that we need some kind of value synchronization for readers that is tied only to the specific cache value, not to the overall cache.