use `broker_handle` to avoid overloading the `broker` fn (#100)

pull/109/head
Zach Kemp 5 years ago committed by Stjepan Glavina
parent 794c12fe7e
commit 6d6328a9c8

@ -25,7 +25,7 @@ async fn server(addr: impl ToSocketAddrs) -> Result<()> {
let listener = TcpListener::bind(addr).await?; let listener = TcpListener::bind(addr).await?;
let (broker_sender, broker_receiver) = mpsc::unbounded(); let (broker_sender, broker_receiver) = mpsc::unbounded();
let broker = task::spawn(broker(broker_receiver)); let broker_handle = task::spawn(broker(broker_receiver));
let mut incoming = listener.incoming(); let mut incoming = listener.incoming();
while let Some(stream) = incoming.next().await { while let Some(stream) = incoming.next().await {
let stream = stream?; let stream = stream?;
@ -33,7 +33,7 @@ async fn server(addr: impl ToSocketAddrs) -> Result<()> {
spawn_and_log_error(client(broker_sender.clone(), stream)); spawn_and_log_error(client(broker_sender.clone(), stream));
} }
drop(broker_sender); // 1 drop(broker_sender); // 1
broker.await?; // 5 broker_handle.await?; // 5
Ok(()) Ok(())
} }
``` ```

@ -130,7 +130,7 @@ async fn server(addr: impl ToSocketAddrs) -> Result<()> {
let listener = TcpListener::bind(addr).await?; let listener = TcpListener::bind(addr).await?;
let (broker_sender, broker_receiver) = mpsc::unbounded(); let (broker_sender, broker_receiver) = mpsc::unbounded();
let broker = task::spawn(broker(broker_receiver)); let broker_handle = task::spawn(broker(broker_receiver));
let mut incoming = listener.incoming(); let mut incoming = listener.incoming();
while let Some(stream) = incoming.next().await { while let Some(stream) = incoming.next().await {
let stream = stream?; let stream = stream?;
@ -138,7 +138,7 @@ async fn server(addr: impl ToSocketAddrs) -> Result<()> {
spawn_and_log_error(client(broker_sender.clone(), stream)); spawn_and_log_error(client(broker_sender.clone(), stream));
} }
drop(broker_sender); drop(broker_sender);
broker.await; broker_handle.await;
Ok(()) Ok(())
} }

Loading…
Cancel
Save