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

@@ -51,7 +51,7 @@ impl ReadHandle {
// Vérifier validité dans le cache
let cache = crate::manager::audio_cache()?;
if cache.is_valid_pk(&cache_pk) {
if cache.is_valid_pk(&cache_pk).await {
// Valide, avancer le curseur et retourner
self.cursor.fetch_add(1, Ordering::SeqCst);
return Ok(Some(PlaylistTrack::new(cache_pk)));
@@ -92,7 +92,7 @@ impl ReadHandle {
Some(record) => {
// Vérifier validité
let cache = crate::manager::audio_cache()?;
if cache.is_valid_pk(&record.cache_pk) {
if cache.is_valid_pk(&record.cache_pk).await {
Ok(Some(PlaylistTrack::new(record.cache_pk.clone())))
} else {
Ok(None)
@@ -125,7 +125,7 @@ impl ReadHandle {
for i in pos..core.len() {
if let Some(record) = core.get(i) {
if cache.is_valid_pk(&record.cache_pk) {
if cache.is_valid_pk(&record.cache_pk).await {
count += 1;
}
}
@@ -200,7 +200,7 @@ impl ReadHandle {
};
// Vérifier validité
if !cache.is_valid_pk(&record.cache_pk) {
if !cache.is_valid_pk(&record.cache_pk).await {
continue;
}

View File

@@ -30,7 +30,7 @@ impl WriteHandle {
// Vérifier que le pk existe dans le cache
let cache = crate::manager::audio_cache()?;
if !cache.is_valid_pk(&cache_pk) {
if !cache.is_valid_pk(&cache_pk).await {
return Err(crate::Error::CacheEntryNotFound(cache_pk));
}
@@ -59,7 +59,7 @@ impl WriteHandle {
// Vérifier tous les pks d'abord
let cache = crate::manager::audio_cache()?;
for pk in &cache_pks {
if !cache.is_valid_pk(pk) {
if !cache.is_valid_pk(pk).await {
return Err(crate::Error::CacheEntryNotFound(pk.clone()));
}
}