initial prototype
This commit is contained in:
36
src/state.rs
Normal file
36
src/state.rs
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user