Skip to content
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

save and delete concurrently #25

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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);

Check warning on line 82 in src/session_store.rs

View check run for this annotation

Codecov / codecov/patch

src/session_store.rs#L81-L82

Added lines #L81 - L82 were not covered by tests

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

Check warning on line 84 in src/session_store.rs

View check run for this annotation

Codecov / codecov/patch

src/session_store.rs#L84

Added line #L84 was not covered by tests

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

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);

Check warning on line 130 in src/session_store.rs

View check run for this annotation

Codecov / codecov/patch

src/session_store.rs#L129-L130

Added lines #L129 - L130 were not covered by tests

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

Check warning on line 132 in src/session_store.rs

View check run for this annotation

Codecov / codecov/patch

src/session_store.rs#L132

Added line #L132 was not covered by tests

Ok(())
}
}