Commit ca9735cc1a

ca9735cc1aade554a08ef4efca00e6cd9c0273bb

parent: 48432107f4

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-03-01 18:38 UTC

server: Don't pass a response receiver sender to the send method.

Layout: unified · split

src/server.rs +5 −3
@@ -334,13 +334,13 @@ impl MatrixServer {
334 }; 334 };
335 335
336 let (tx, rx) = async_channel(1000); 336 let (tx, rx) = async_channel(1000);
337 runtime.spawn(MatrixServer::sync_loop(client.clone(), tx.clone())); 337 runtime.spawn(MatrixServer::sync_loop(client.clone(), tx));
338 let response_receiver = Weechat::spawn( 338 let response_receiver = Weechat::spawn(
339 MatrixServer::response_receiver(rx, Rc::downgrade(&self.inner)), 339 MatrixServer::response_receiver(rx, Rc::downgrade(&self.inner)),
340 ); 340 );
341 341
342 let (client_sender, client_receiver) = async_channel(10); 342 let (client_sender, client_receiver) = async_channel(10);
343 runtime.spawn(MatrixServer::send_loop(client, client_receiver, tx)); 343 runtime.spawn(MatrixServer::send_loop(client, client_receiver));
344 344
345 let mut connected_state = server.connected_state.borrow_mut(); 345 let mut connected_state = server.connected_state.borrow_mut();
346 346
@@ -485,7 +485,6 @@ impl MatrixServer {
485 pub async fn send_loop( 485 pub async fn send_loop(
486 mut client: AsyncClient, 486 mut client: AsyncClient,
487 channel: Receiver<ServerMessage>, 487 channel: Receiver<ServerMessage>,
488 sender: Sender<Result<ThreadMessage, String>>,
489 ) { 488 ) {
490 while let Some(message) = channel.recv().await { 489 while let Some(message) = channel.recv().await {
491 match message { 490 match message {
@@ -498,6 +497,9 @@ impl MatrixServer {
498 relates_to: None, 497 relates_to: None,
499 }); 498 });
500 499
500 // TODO awaiting here means we can only send one message
501 // at a time, we need to spawn a task here and return a
502 // oneshot channel that the caller can await.
501 let ret = client.room_send(&room_id, content).await; 503 let ret = client.room_send(&room_id, content).await;
502 504
503 match ret { 505 match ret {