Files
solana/sdk/src/exit.rs
mergify[bot] 893df9b277 Rename ValidatorExit and move to sdk (#17728) (#17729)
(cherry picked from commit 3a647c4bea)

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
2021-06-04 04:38:49 +00:00

31 lines
606 B
Rust

use std::fmt;
#[derive(Default)]
pub struct Exit {
exited: bool,
exits: Vec<Box<dyn FnOnce() + Send + Sync>>,
}
impl Exit {
pub fn register_exit(&mut self, exit: Box<dyn FnOnce() + Send + Sync>) {
if self.exited {
exit();
} else {
self.exits.push(exit);
}
}
pub fn exit(&mut self) {
self.exited = true;
for exit in self.exits.drain(..) {
exit();
}
}
}
impl fmt::Debug for Exit {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} exits", self.exits.len())
}
}