ctrl c listener for producer
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user