Skip to content

Commit

Permalink
src: mavlink, stream: Prefer Interval::tick over sleep for periodic t…
Browse files Browse the repository at this point in the history
…okio tasks
  • Loading branch information
joaoantoniocardoso authored and patrickelectric committed Mar 15, 2024
1 parent 3f6e90d commit 98223ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/mavlink/mavlink_camera.rs
Expand Up @@ -138,8 +138,9 @@ impl MavlinkCameraInner {
let component_id = camera.component.component_id;
let system_id = camera.component.system_id;

let mut period = tokio::time::interval(tokio::time::Duration::from_secs(1));
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
period.tick().await;

let header = mavlink::MavHeader {
system_id,
Expand Down
4 changes: 3 additions & 1 deletion src/stream/gst/utils.rs
Expand Up @@ -78,8 +78,10 @@ pub async fn wait_for_element_state_async(
) -> Result<()> {
let mut trials = 1000 * timeout_time_secs / polling_time_millis;

let mut period = tokio::time::interval(tokio::time::Duration::from_millis(polling_time_millis));

loop {
tokio::time::sleep(tokio::time::Duration::from_millis(polling_time_millis)).await;
period.tick().await;

let Some(element) = element_weak.upgrade() else {
return Err(anyhow!("Cannot access Element"));
Expand Down
3 changes: 2 additions & 1 deletion src/stream/mod.rs
Expand Up @@ -98,8 +98,9 @@ impl Stream {

let mut video_and_stream_information = video_and_stream_information;

let mut period = tokio::time::interval(tokio::time::Duration::from_millis(100));
loop {
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
period.tick().await;

if !state
.read()
Expand Down

0 comments on commit 98223ac

Please sign in to comment.