initial prototype

This commit is contained in:
2025-07-19 15:35:04 +02:00
commit 673a0967b2
8 changed files with 1948 additions and 0 deletions

36
src/state.rs Normal file
View File

@@ -0,0 +1,36 @@
use bytes::Bytes;
use tokio::sync::{Notify, RwLock};
pub struct AppState {
pub chunks: RwLock<Vec<Bytes>>,
pub complete: RwLock<bool>,
pub notify: Notify,
}
impl AppState {
pub fn new() -> Self {
Self {
chunks: RwLock::new(Vec::new()),
complete: RwLock::new(false),
notify: Notify::new(),
}
}
pub async fn add_chunk(&self, chunk: Bytes) {
self.chunks.write().await.push(chunk);
self.notify.notify_waiters();
}
pub async fn mark_complete(&self) {
*self.complete.write().await = true;
self.notify.notify_waiters();
}
pub async fn is_complete(&self) -> bool {
*self.complete.read().await
}
pub async fn chunk_count(&self) -> usize {
self.chunks.read().await.len()
}
}