Call watch_whole either way
This commit is contained in:
parent
adf3d4ef31
commit
711580f270
|
@ -207,16 +207,28 @@ impl GatewayHandle {
|
||||||
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) {
|
||||||
let object = channel.clone();
|
let object = channel.clone();
|
||||||
let inner_object = object.read().unwrap();
|
drop(store);
|
||||||
inner_object.downcast_ref::<T>().unwrap_or_else(|| {
|
object
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.downcast_ref::<T>()
|
||||||
|
.unwrap_or_else(|| {
|
||||||
panic!(
|
panic!(
|
||||||
"Snowflake {} already exists in the store, but it is not of type T.",
|
"Snowflake {} already exists in the store, but it is not of type T.",
|
||||||
id
|
id
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let ptr = Arc::into_raw(object.clone());
|
let ptr = Arc::into_raw(object.clone());
|
||||||
//unsafe { println!("{:?}", Arc::from_raw(ptr as *const RwLock<T>).clone()) };
|
// SAFETY:
|
||||||
unsafe { Arc::from_raw(ptr as *const RwLock<T>).clone() }
|
// - We have just checked that the typeid of the `dyn Any ...` matches that of `T`.
|
||||||
|
// - This operation doesn't read or write any shared data, and thus cannot cause a data race
|
||||||
|
// - The reference count is not being modified
|
||||||
|
let downcasted = unsafe { Arc::from_raw(ptr as *const RwLock<T>).clone() };
|
||||||
|
let object = downcasted.read().unwrap().clone();
|
||||||
|
|
||||||
|
let watched_object = object.watch_whole(self).await;
|
||||||
|
*downcasted.write().unwrap() = watched_object;
|
||||||
|
downcasted
|
||||||
} else {
|
} else {
|
||||||
let id = object.read().unwrap().id();
|
let id = object.read().unwrap().id();
|
||||||
let object = object.read().unwrap().clone();
|
let object = object.read().unwrap().clone();
|
||||||
|
@ -499,16 +511,18 @@ impl Gateway {
|
||||||
Ok(message) => {
|
Ok(message) => {
|
||||||
$(
|
$(
|
||||||
let mut message: $message_type = message;
|
let mut message: $message_type = message;
|
||||||
let mut store = self.store.lock().await;
|
let store = self.store.lock().await;
|
||||||
if let Some(to_update) = store.get(&message.id()) {
|
if let Some(to_update) = store.get(&message.id()) {
|
||||||
let object = to_update.clone();
|
let object = to_update.clone();
|
||||||
let inner_object = object.read().unwrap();
|
let inner_object = object.read().unwrap();
|
||||||
if let Some(_) = inner_object.downcast_ref::<$update_type>() {
|
if let Some(_) = inner_object.downcast_ref::<$update_type>() {
|
||||||
let ptr = Arc::into_raw(object.clone());
|
let ptr = Arc::into_raw(object.clone());
|
||||||
|
// SAFETY:
|
||||||
|
// - We have just checked that the typeid of the `dyn Any ...` matches that of `T`.
|
||||||
|
// - This operation doesn't read or write any shared data, and thus cannot cause a data race
|
||||||
|
// - The reference count is not being modified
|
||||||
let downcasted = unsafe { Arc::from_raw(ptr as *const RwLock<$update_type>).clone() };
|
let downcasted = unsafe { Arc::from_raw(ptr as *const RwLock<$update_type>).clone() };
|
||||||
drop(inner_object);
|
drop(inner_object);
|
||||||
store.insert(message.id(), downcasted.clone());
|
|
||||||
println!("yippie");
|
|
||||||
message.set_json(json.to_string());
|
message.set_json(json.to_string());
|
||||||
message.update(downcasted.clone());
|
message.update(downcasted.clone());
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue