Switch to unbounded receiver for vault

This commit is contained in:
Joscha 2022-06-23 22:41:02 +02:00
parent e6af7e6aa1
commit 5abda48b86
2 changed files with 11 additions and 11 deletions

View file

@ -17,13 +17,13 @@ enum Request {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Vault { pub struct Vault {
tx: mpsc::Sender<Request>, tx: mpsc::UnboundedSender<Request>,
} }
impl Vault { impl Vault {
pub async fn close(&self) { pub async fn close(&self) {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
let _ = self.tx.send(Request::Close(tx)).await; let _ = self.tx.send(Request::Close(tx));
let _ = rx.await; let _ = rx.await;
} }
@ -35,7 +35,7 @@ impl Vault {
} }
} }
fn run(conn: Connection, mut rx: mpsc::Receiver<Request>) { fn run(conn: Connection, mut rx: mpsc::UnboundedReceiver<Request>) {
while let Some(request) = rx.blocking_recv() { while let Some(request) = rx.blocking_recv() {
match request { match request {
Request::Close(tx) => { Request::Close(tx) => {
@ -71,7 +71,7 @@ pub fn launch(path: &Path) -> rusqlite::Result<Vault> {
migrate::migrate(&mut conn)?; migrate::migrate(&mut conn)?;
let (tx, rx) = mpsc::channel(8); let (tx, rx) = mpsc::unbounded_channel();
thread::spawn(move || run(conn, rx)); thread::spawn(move || run(conn, rx));
Ok(Vault { tx }) Ok(Vault { tx })
} }

View file

@ -48,7 +48,7 @@ impl From<EuphRequest> for Request {
} }
pub struct EuphVault { pub struct EuphVault {
pub(super) tx: mpsc::Sender<Request>, pub(super) tx: mpsc::UnboundedSender<Request>,
pub(super) room: String, pub(super) room: String,
} }
@ -62,7 +62,7 @@ impl MsgStore<EuphMsg> for EuphVault {
id: *id, id: *id,
result: tx, result: tx,
}; };
let _ = self.tx.send(request.into()).await; let _ = self.tx.send(request.into());
rx.await.unwrap() rx.await.unwrap()
} }
@ -74,7 +74,7 @@ impl MsgStore<EuphMsg> for EuphVault {
root: *root, root: *root,
result: tx, result: tx,
}; };
let _ = self.tx.send(request.into()).await; let _ = self.tx.send(request.into());
rx.await.unwrap() rx.await.unwrap()
} }
@ -86,7 +86,7 @@ impl MsgStore<EuphMsg> for EuphVault {
root: *root, root: *root,
result: tx, result: tx,
}; };
let _ = self.tx.send(request.into()).await; let _ = self.tx.send(request.into());
rx.await.unwrap() rx.await.unwrap()
} }
@ -98,7 +98,7 @@ impl MsgStore<EuphMsg> for EuphVault {
root: *root, root: *root,
result: tx, result: tx,
}; };
let _ = self.tx.send(request.into()).await; let _ = self.tx.send(request.into());
rx.await.unwrap() rx.await.unwrap()
} }
@ -109,7 +109,7 @@ impl MsgStore<EuphMsg> for EuphVault {
room: self.room.clone(), room: self.room.clone(),
result: tx, result: tx,
}; };
let _ = self.tx.send(request.into()).await; let _ = self.tx.send(request.into());
rx.await.unwrap() rx.await.unwrap()
} }
@ -120,7 +120,7 @@ impl MsgStore<EuphMsg> for EuphVault {
room: self.room.clone(), room: self.room.clone(),
result: tx, result: tx,
}; };
let _ = self.tx.send(request.into()).await; let _ = self.tx.send(request.into());
rx.await.unwrap() rx.await.unwrap()
} }
} }