use super::key::RefreshKey;
use std::cell::RefCell;
use std::collections::HashSet;
thread_local! {
pub static TX_REFRESH_QUEUE: RefCell<HashSet<RefreshKey>> = RefCell::new(HashSet::new());
pub static TX_CRASH_RECOVERY_CHECKED: RefCell<HashSet<String>> = RefCell::new(HashSet::new());
}
pub fn replace_queue(new_queue: HashSet<RefreshKey>) {
TX_REFRESH_QUEUE.with(|q| {
*q.borrow_mut() = new_queue;
});
}
pub fn get_queue_size() -> usize {
TX_REFRESH_QUEUE.with(|q| q.borrow().len())
}
pub fn get_queue_contents() -> Vec<RefreshKey> {
TX_REFRESH_QUEUE.with(|q| q.borrow().iter().cloned().collect())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_queue_thread_local() {
TX_REFRESH_QUEUE.with(|q| {
let mut queue = q.borrow_mut();
queue.insert(RefreshKey::pk("user", 1));
assert_eq!(queue.len(), 1);
});
TX_REFRESH_QUEUE.with(|q| q.borrow_mut().clear());
}
}