use crate::persistence::chunking::ChunkIter;
use js_sys::Uint8Array;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct PersistenceIterator {
pub(crate) iter: ChunkIter<'static>,
pub(crate) liveness: Arc<AtomicBool>,
}
#[wasm_bindgen]
impl PersistenceIterator {
#[wasm_bindgen]
pub fn next_chunk(&mut self) -> Option<Uint8Array> {
assert!(
self.liveness.load(Ordering::Acquire),
"EdgeVec Use-After-Free: EdgeVec instance was freed while PersistenceIterator is still active. Do not call .free() on EdgeVec while iterating."
);
self.iter.next().map(|chunk| {
Uint8Array::from(&chunk[..])
})
}
}