Replace use of Arc<RwLock<T>> with Shared<T>

This commit is contained in:
bitfl0wer 2024-01-21 17:07:19 +01:00
parent 92654989e8
commit 39b1f1fa72
2 changed files with 11 additions and 12 deletions

View File

@ -42,8 +42,8 @@ impl GatewayHandle {
pub async fn observe<T: Updateable + Clone + Debug + Composite<T>>( pub async fn observe<T: Updateable + Clone + Debug + Composite<T>>(
&self, &self,
object: Arc<RwLock<T>>, object: Shared<T>,
) -> Arc<RwLock<T>> { ) -> Shared<T> {
let mut store = self.store.lock().await; let mut store = self.store.lock().await;
let id = object.read().unwrap().id(); let id = object.read().unwrap().id();
if let Some(channel) = store.get(&id) { if let Some(channel) = store.get(&id) {
@ -84,7 +84,7 @@ impl GatewayHandle {
/// with all of its observable fields being observed. /// with all of its observable fields being observed.
pub async fn observe_and_into_inner<T: Updateable + Clone + Debug + Composite<T>>( pub async fn observe_and_into_inner<T: Updateable + Clone + Debug + Composite<T>>(
&self, &self,
object: Arc<RwLock<T>>, object: Shared<T>,
) -> T { ) -> T {
let channel = self.observe(object.clone()).await; let channel = self.observe(object.clone()).await;
let object = channel.read().unwrap().clone(); let object = channel.read().unwrap().clone();

View File

@ -1,6 +1,5 @@
use std::sync::{Arc, RwLock}; use chorus::gateway::{Gateway, Shared};
use chorus::types::Composite;
use chorus::gateway::Gateway;
use chorus::{ use chorus::{
instance::{ChorusUser, Instance}, instance::{ChorusUser, Instance},
types::{ types::{
@ -16,9 +15,9 @@ pub(crate) struct TestBundle {
pub urls: UrlBundle, pub urls: UrlBundle,
pub user: ChorusUser, pub user: ChorusUser,
pub instance: Instance, pub instance: Instance,
pub guild: Arc<RwLock<Guild>>, pub guild: Shared<Guild>,
pub role: Arc<RwLock<RoleObject>>, pub role: Shared<RoleObject>,
pub channel: Arc<RwLock<Channel>>, pub channel: Shared<Channel>,
} }
#[allow(unused)] #[allow(unused)]
@ -119,9 +118,9 @@ pub(crate) async fn setup() -> TestBundle {
urls, urls,
user, user,
instance, instance,
guild: Arc::new(RwLock::new(guild)), guild: guild.to_shared(),
role: Arc::new(RwLock::new(role)), role: role.to_shared(),
channel: Arc::new(RwLock::new(channel)), channel: channel.to_shared(),
} }
} }