Skip to content

Commit 666eba4

Browse files
committed
feat(base): Create EventCacheStoreLock.
1 parent 2c26a6a commit 666eba4

File tree

1 file changed

+32
-5
lines changed
  • crates/matrix-sdk-base/src/event_cache_store

1 file changed

+32
-5
lines changed

crates/matrix-sdk-base/src/event_cache_store/mod.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
//! into the event cache for the actual storage. By default this brings an
2020
//! in-memory store.
2121
22-
use std::{str::Utf8Error, sync::Arc};
22+
use std::{fmt, str::Utf8Error, sync::Arc};
2323

2424
#[cfg(any(test, feature = "testing"))]
2525
#[macro_use]
2626
pub mod integration_tests;
2727
mod memory_store;
2828
mod traits;
2929

30-
use matrix_sdk_common::store_locks::BackingStore;
30+
use matrix_sdk_common::store_locks::{BackingStore, CrossProcessStoreLock};
3131
pub use matrix_sdk_store_encryption::Error as StoreEncryptionError;
3232

3333
#[cfg(any(test, feature = "testing"))]
@@ -85,10 +85,8 @@ impl EventCacheStoreError {
8585
/// An `EventCacheStore` specific result type.
8686
pub type Result<T, E = EventCacheStoreError> = std::result::Result<T, E>;
8787

88-
/// The public API to read the event cache store: it is behind a cross-process
89-
/// lock.
9088
#[derive(Clone, Debug)]
91-
pub struct LockableEventCacheStore(Arc<dyn EventCacheStore<Error = EventCacheStoreError>>);
89+
struct LockableEventCacheStore(Arc<DynEventCacheStore>);
9290

9391
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
9492
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
@@ -104,3 +102,32 @@ impl BackingStore for LockableEventCacheStore {
104102
self.0.try_take_leased_lock(lease_duration_ms, key, holder).await
105103
}
106104
}
105+
106+
/// The high-level public type to represent an `EventCacheStore` lock.
107+
pub struct EventCacheStoreLock {
108+
cross_process_lock: CrossProcessStoreLock<LockableEventCacheStore>,
109+
store: Arc<DynEventCacheStore>,
110+
}
111+
112+
impl fmt::Debug for EventCacheStoreLock {
113+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
114+
formatter.debug_struct("EventCacheStoreLock").finish_non_exhaustive()
115+
}
116+
}
117+
118+
impl EventCacheStoreLock {
119+
pub fn new(store: Arc<DynEventCacheStore>, key: String, holder: String) -> Self {
120+
Self {
121+
cross_process_lock: CrossProcessStoreLock::new(
122+
LockableEventCacheStore(store.clone()),
123+
key,
124+
holder,
125+
),
126+
store,
127+
}
128+
}
129+
130+
pub async fn lock(&self) -> &Arc<DynEventCacheStore> {
131+
todo!()
132+
}
133+
}

0 commit comments

Comments
 (0)