use crate::state::WithOverlay;
use gear_core::message::StoredDispatch;
use std::{collections::VecDeque, thread::LocalKey};
thread_local! {
pub(super) static DISPATCHES_QUEUE: WithOverlay<VecDeque<StoredDispatch>> = Default::default();
}
fn storage() -> &'static LocalKey<WithOverlay<VecDeque<StoredDispatch>>> {
&DISPATCHES_QUEUE
}
#[derive(Debug, Clone, Default)]
pub(crate) struct QueueManager;
impl QueueManager {
pub(crate) fn push_back(&self, dispatch: StoredDispatch) {
storage().with(|queue| queue.data_mut().push_back(dispatch));
}
pub(crate) fn push_front(&self, dispatch: StoredDispatch) {
storage().with(|queue| queue.data_mut().push_front(dispatch));
}
pub(crate) fn pop_front(&self) -> Option<StoredDispatch> {
storage().with(|queue| queue.data_mut().pop_front())
}
pub(crate) fn clear(&self) {
storage().with(|queue| queue.data_mut().clear())
}
pub(crate) fn len(&self) -> usize {
storage().with(|queue| queue.data().len())
}
}