Cancel threads in stream witha drop guard

This commit is contained in:
QuantumEntangledAndy committed 2023-09-21 11:23:20 +07:00
1 parent 9f02f6dead
commit 87e32f571a
1 file changed
+2
+2
View File
@@ -649,6 +649,7 @@ async fn stream_run(
log::info!("{}: Avaliable at {}", name, paths.join(", "));
let stream_cancel = CancellationToken::new();
let drop_guard = stream_cancel.clone().drop_guard();
let mut set = JoinSet::new();
// Wait for new media client data to come in from the factory
while let Some(mut client_data) = client_rx.recv().await {
@@ -861,6 +862,7 @@ async fn stream_run(
// Cancel any remaining threads that are trying to send data
// Although it should be finished already when the appsrcs are dropped
stream_cancel.cancel();
drop(drop_guard);
while set.join_next().await.is_some() {}
log::trace!("Stream done");
AnyResult::Ok(())