fix cache bug

Signed-off-by: mujunxiang <1948535941@qq.com>
This commit is contained in:
mujunxiang
2024-11-20 09:47:10 +08:00
parent e6d5fe328d
commit 1d81a9e40f
2 changed files with 13 additions and 12 deletions
+4 -2
View File
@@ -1,5 +1,7 @@
use std::{
fmt::Debug,
future::Future,
pin::Pin,
ptr,
sync::{
atomic::{AtomicPtr, AtomicU64, Ordering},
@@ -12,7 +14,7 @@ use tokio::{spawn, sync::Mutex};
use crate::error::Result;
type UpdateFn<T> = Box<dyn Fn() -> Result<T> + Send + Sync>;
pub type UpdateFn<T> = Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<T>> + Send>> + Send + Sync + 'static>;
#[derive(Clone, Debug, Default)]
pub struct Opts {
@@ -96,7 +98,7 @@ impl<T: Clone + Debug + Send + 'static> Cache<T> {
}
async fn update(&self) -> Result<()> {
match (self.update_fn)() {
match (self.update_fn)().await {
Ok(val) => {
self.val.store(Box::into_raw(Box::new(val)), Ordering::SeqCst);
let now = SystemTime::now()