Skip to content

Commit

Permalink
dilation: Use async lock instead of RefCell for wormhole connection
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Dec 9, 2023
1 parent a584c16 commit f451c98
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/dilation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Rc;

use futures::executor;

Expand All @@ -22,22 +22,22 @@ mod manager;
type WormholeConnection = WormholeConnectionDefault;

pub struct WormholeConnectionDefault {
wormhole: Rc<RefCell<Wormhole>>,
wormhole: Rc<async_std::sync::Mutex<Wormhole>>,
}

#[cfg_attr(test, mockall::automock)]
impl WormholeConnectionDefault {
fn new(wormhole: Wormhole) -> Self {
Self {
wormhole: Rc::new(RefCell::new(wormhole)),
wormhole: Rc::new(async_std::sync::Mutex::new(wormhole)),
}
}

async fn receive_json<T>(&self) -> Result<T, WormholeError>
where
T: for<'a> serde::Deserialize<'a> + 'static,
{
let message = self.wormhole.borrow_mut().receive_json().await;
let message = self.wormhole.lock().await.receive_json().await;
match message {
Ok(result) => match result {
Ok(result) => Ok(result),
Expand All @@ -49,7 +49,8 @@ impl WormholeConnectionDefault {

async fn send_json(&self, command: &ProtocolCommand) -> Result<(), WormholeError> {
self.wormhole
.borrow_mut()
.lock()
.await
.send_json_with_phase(command, Phase::dilation)
.await
}
Expand Down

0 comments on commit f451c98

Please sign in to comment.