27 lines
601 B
Rust
27 lines
601 B
Rust
|
use parking_lot::Mutex;
|
||
|
use types::SignedBeaconBlockHeader;
|
||
|
|
||
|
#[derive(Debug, Default)]
|
||
|
pub struct BlockQueue {
|
||
|
blocks: Mutex<Vec<SignedBeaconBlockHeader>>,
|
||
|
}
|
||
|
|
||
|
impl BlockQueue {
|
||
|
pub fn queue(&self, block_header: SignedBeaconBlockHeader) {
|
||
|
self.blocks.lock().push(block_header)
|
||
|
}
|
||
|
|
||
|
pub fn dequeue(&self) -> Vec<SignedBeaconBlockHeader> {
|
||
|
let mut blocks = self.blocks.lock();
|
||
|
std::mem::replace(&mut *blocks, vec![])
|
||
|
}
|
||
|
|
||
|
pub fn len(&self) -> usize {
|
||
|
self.blocks.lock().len()
|
||
|
}
|
||
|
|
||
|
pub fn is_empty(&self) -> bool {
|
||
|
self.len() == 0
|
||
|
}
|
||
|
}
|