ctrl c listener for producer

This commit is contained in:
sergeysav committed 2024-10-19 16:01:27 -07:00
1 parent f47512010f
commit c9bf33ab6c
3 files changed
+21 -2

No files matched your search

+10 -1
View File
@@ -123,9 +123,18 @@ async fn main() -> Result<(), Box<dyn Error>> {
let sin_tlm_handle = tlm.register("simple_producer/sin".into(), TelemetryDataType::Float32).await?;
let cos_tlm_handle = tlm.register("simple_producer/cos".into(), TelemetryDataType::Float64).await?;
let cancellation_token = CancellationToken::new();
{
let cancellation_token = cancellation_token.clone();
tokio::spawn(async move {
let _ = tokio::signal::ctrl_c().await;
cancellation_token.cancel();
});
}
let mut next_time = Instant::now();
let mut index = 0;
for _ in 0..100 {
while !cancellation_token.is_cancelled() {
next_time += Duration::from_millis(100);
index += 10;
tokio::time::sleep_until(next_time).await;