-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Bug in the Arc<E> ref count? #497
Comments
Hi. Technically, it is not a bug, but in the future, I would change the behavior of the method and the return type to If we add // Cargo.toml
// [dependencies]
//
// crossbeam-epoch = "0.9.18"
// moka = { version = "0.12.10", features = ["future"] }
// tokio = { version = "1.43.0", features = ["rt-multi-thread", "macros"] }
...
let r = cache
.try_get_with("abc".to_string(), async { Err(42) })
.await;
crossbeam_epoch::pin().flush(); // Add this.
match r {
... But For now, you can use use moka::{future::Cache, ops::compute::Op, policy::EvictionPolicy};
#[tokio::main]
async fn main() {
let cache: Cache<String, String> = Cache::builder()
.max_capacity(10)
.eviction_policy(EvictionPolicy::tiny_lfu())
.build();
let r = cache
.entry("abc".to_string())
.and_try_compute_with(|v| async move {
if v.is_none() {
Err(42)
} else {
Ok(Op::Nop)
}
})
.await;
assert!(matches!(r, Err(42)));
} Note that
In the future, I would change the behavior of The reason that the I said twice, the one in the first code snippet above is the second one. The first one is in the |
Hi,
As documented and explained in #328 the return from
try_*
fns in the library is aResult<T, Arc<E>>
And the idiomatic way to extract the error to pass it along, is to call
Arc::into_inner
But from my observations, it seems there is a mismatch in the behaviour this code snippet is showing
The
strong_count
actually shows up as 2 making the into_inner method unusable to extract the inner Error.Is there something missing in my understanding?
Or is this a bug?
The text was updated successfully, but these errors were encountered: