Skip to content

Commit

Permalink
save and delete concurrently (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcountryman authored Oct 3, 2023
1 parent 725514c commit 221452a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ tokio = ["dep:tokio"]
[dependencies]
async-trait = "0.1.73"
http = "0.2.9"
futures = { version = "0.3.28", default-features = false, features = [
"async-await",
] }
parking_lot = { version = "0.12.1", features = ["serde"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
Expand Down
26 changes: 10 additions & 16 deletions src/session_store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! An arbitrary store which houses the session data.

use async_trait::async_trait;
use futures::TryFutureExt;

use crate::session::{Session, SessionId, SessionRecord};

Expand Down Expand Up @@ -77,14 +78,10 @@ where
type Error = CachingStoreError<Cache, Store>;

async fn save(&self, session_record: &SessionRecord) -> Result<(), Self::Error> {
self.store
.save(session_record)
.await
.map_err(Self::Error::Store)?;
self.cache
.save(session_record)
.await
.map_err(Self::Error::Cache)?;
let cache_save_fut = self.store.save(session_record).map_err(Self::Error::Store);
let store_save_fut = self.cache.save(session_record).map_err(Self::Error::Cache);

futures::try_join!(cache_save_fut, store_save_fut)?;

Ok(())
}
Expand Down Expand Up @@ -129,14 +126,11 @@ where
}

async fn delete(&self, session_id: &SessionId) -> Result<(), Self::Error> {
self.store
.delete(session_id)
.await
.map_err(Self::Error::Store)?;
self.cache
.delete(session_id)
.await
.map_err(Self::Error::Cache)?;
let store_delete_fut = self.store.delete(session_id).map_err(Self::Error::Store);
let cache_delete_fut = self.cache.delete(session_id).map_err(Self::Error::Cache);

futures::try_join!(store_delete_fut, cache_delete_fut)?;

Ok(())
}
}

0 comments on commit 221452a

Please sign in to comment.