aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/network.rs
diff options
context:
space:
mode:
authorEskil Q <eskilq@kth.se>2021-01-06 18:31:49 +0100
committerEskil Q <eskilq@kth.se>2021-01-06 18:31:49 +0100
commit02e6f2b84d72294b29a1698c1b73fbb5697815da (patch)
treeaf85a0277c89ef7983f79ff795acf1bd94eee848 /mumd/src/network.rs
parentb15e010a6bebc7b7c6b8afb1b51f2673d0695e06 (diff)
downloadmum-02e6f2b84d72294b29a1698c1b73fbb5697815da.tar.gz
clean up network::run_until
Diffstat (limited to 'mumd/src/network.rs')
-rw-r--r--mumd/src/network.rs41
1 files changed, 14 insertions, 27 deletions
diff --git a/mumd/src/network.rs b/mumd/src/network.rs
index 03bc436..75b983e 100644
--- a/mumd/src/network.rs
+++ b/mumd/src/network.rs
@@ -10,6 +10,7 @@ use futures::join;
use futures::pin_mut;
use futures::select;
use tokio::sync::watch;
+use log::*;
use crate::state::StatePhase;
@@ -36,16 +37,14 @@ pub enum VoiceStreamType {
UDP,
}
-async fn run_until<T, F, G, H>(
+async fn run_until<F, G>(
phase_checker: impl Fn(StatePhase) -> bool,
- mut generator: impl FnMut() -> F,
- mut handler: impl FnMut(T) -> G,
- mut shutdown: impl FnMut() -> H,
+ fut: F,
+ mut shutdown: impl FnMut() -> G,
mut phase_watcher: watch::Receiver<StatePhase>,
) where
- F: Future<Output = Option<T>>,
+ F: Future<Output = ()>,
G: Future<Output = ()>,
- H: Future<Output = ()>,
{
let (tx, rx) = oneshot::channel();
let phase_transition_block = async {
@@ -55,32 +54,20 @@ async fn run_until<T, F, G, H>(
break;
}
}
- tx.send(true).unwrap();
+ if tx.send(true).is_err() {
+ warn!("future resolved before it could be cancelled");
+ }
};
let main_block = async {
let rx = rx.fuse();
pin_mut!(rx);
- loop {
- let packet_recv = generator().fuse();
- pin_mut!(packet_recv);
- let exitor = select! {
- data = packet_recv => Some(data),
- _ = rx => None
- };
- match exitor {
- None => {
- break;
- }
- Some(None) => {
- //warn!("Channel closed before disconnect command"); //TODO make me informative
- break;
- }
- Some(Some(data)) => {
- handler(data).await;
- }
- }
- }
+ let fut = fut.fuse();
+ pin_mut!(fut);
+ select! {
+ _ = fut => (),
+ _ = rx => (),
+ };
shutdown().await;
};