imago/sync_primitives/
async_impl.rs1use std::sync::Arc;
4use tokio::sync::{OwnedRwLockReadGuard, OwnedRwLockWriteGuard};
5
6#[derive(Debug, Default)]
8pub(crate) struct OwnedRwLock<T>(Arc<tokio::sync::RwLock<T>>);
9
10impl<T> Clone for OwnedRwLock<T> {
11 fn clone(&self) -> Self {
12 OwnedRwLock(Arc::clone(&self.0))
13 }
14}
15
16impl<T> OwnedRwLock<T> {
17 pub async fn read(&self) -> OwnedRwLockReadGuard<T> {
19 Arc::clone(&self.0).read_owned().await
20 }
21
22 pub async fn write(&self) -> OwnedRwLockWriteGuard<T> {
24 Arc::clone(&self.0).write_owned().await
25 }
26}