Handle graceful shutdown in image command

This commit is contained in:
Andrew committed 2023-08-03 18:07:42 +07:00
1 parent 42ee790512
commit 2f557f777d
5 files changed
+138 -82

No files matched your search

+5 -1
View File
@@ -20,7 +20,6 @@ enum GstControl {
pub(super) struct GstSender {
sender: Sender<GstControl>,
#[allow(dead_code)] // It is used for its automatic drop
set: JoinSet<Result<()>>,
finished: sync::oneshot::Receiver<Result<()>>,
}
@@ -49,6 +48,11 @@ impl GstSender {
}
}
}
pub(super) async fn join(mut self) -> Result<()> {
while self.set.join_next().await.is_some() {}
Ok(())
}
}
pub(super) async fn from_input<T: AsRef<Path>>(
+6
View File
@@ -81,6 +81,9 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
}
debug!("Sending EOS");
let _ = sender.eos().await; // Ignore return because if pipeline is finished this will error
let _ = sender.join().await;
let _ = stream_data.shutdown().await;
} else {
// Simply use the snap command
debug!("Using the snap command");
@@ -90,5 +93,8 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
buffer.write_all(jpeg_data.as_slice()).await?;
}
let _ = camera.logout().await;
camera.disconnect().await?;
Ok(())
}