Make is_valid_pk() async to use tokio::time::sleep

Changed is_valid_pk() from sync to async to properly wait for file
creation without blocking. This is a breaking change but we're in
active development.

Changes:
- is_valid_pk() signature: fn -> async fn
- Replaced std:🧵:sleep with tokio::time::sleep
- Updated all 6 call sites in pmoplaylist to add .await:
  - WriteHandle::push()
  - WriteHandle::push_set()
  - ReadHandle::pop()
  - ReadHandle::peek()
  - ReadHandle::remaining()
  - ReadHandle::get_all()

Benefits:
- Non-blocking wait for file creation during ingestion
- More idiomatic async Rust code
- Better integration with tokio runtime
This commit is contained in:
Claude
2025-11-11 13:33:10 +00:00
parent cdf24b0143
commit 07dcc5bef1
3 changed files with 8 additions and 8 deletions

View File

@@ -144,7 +144,7 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
///
/// Ceci permet le progressive caching: les fichiers en cours de download sont acceptés
/// dès que le prebuffer est atteint, sans attendre le marker de completion.
fn is_valid_pk(&self, pk: &str) -> bool {
async fn is_valid_pk(&self, pk: &str) -> bool {
if self.get_database().get(pk, false).is_err() {
tracing::debug!("is_valid_pk({}): DB entry not found", pk);
return false;
@@ -158,7 +158,7 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
let mut attempts = 0;
while !file_path.exists() && attempts < 100 {
std::thread::sleep(std::time::Duration::from_millis(10));
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
attempts += 1;
}