Skip to content

Commit

Permalink
Add timeout for waiting cache download
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Dec 18, 2023
1 parent 6a6882c commit 8ae1942
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/route/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use tokio::{
fs::{File, OpenOptions},
io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt},
sync::watch,
time::timeout,
};

use crate::{
Expand Down Expand Up @@ -215,7 +216,8 @@ async fn hath(
let mut read_off = 0;
let mut write_off = *rx.borrow();

'watch: while rx.changed().await.is_ok() || write_off != read_off {
let wait_time = Duration::from_secs(30);
'watch: while timeout(wait_time, rx.changed()).await.is_ok_and(|r| r.is_ok()) || write_off != read_off {
write_off = *rx.borrow();

while write_off > read_off {
Expand Down

0 comments on commit 8ae1942

Please sign in to comment.