fix server_cached function

This commit is contained in:
Evan Almloff committed 2023-07-17 09:48:35 -07:00
1 parent 040b9d15a8
commit b05fb16155
4 files changed
+21 -8

No files matched your search

+14 -1
View File
@@ -1,3 +1,5 @@
#![allow(unused)]
use std::sync::atomic::AtomicUsize;
use serde::{de::DeserializeOwned, Serialize};
@@ -34,11 +36,22 @@ impl HTMLDataCursor {
pub fn take<T: DeserializeOwned>(&self) -> Option<T> {
let current = self.index.load(std::sync::atomic::Ordering::SeqCst);
if current >= self.data.len() {
log::error!(
"Tried to take more data than was available, len: {}, index: {}",
self.data.len(),
current
);
return None;
}
let mut cursor = &self.data[current];
self.index.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
Some(postcard::from_bytes(&mut cursor).unwrap())
match postcard::from_bytes(&mut cursor) {
Ok(x) => Some(x),
Err(e) => {
log::error!("Error deserializing data: {:?}", e);
None
}
}
}
}