Rename ValidatorExit and move to sdk (#17728)
This commit is contained in:
30
sdk/src/exit.rs
Normal file
30
sdk/src/exit.rs
Normal file
@ -0,0 +1,30 @@
|
||||
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())
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ pub mod entrypoint;
|
||||
pub mod entrypoint_deprecated;
|
||||
pub mod entrypoint_native;
|
||||
pub mod epoch_info;
|
||||
pub mod exit;
|
||||
pub mod feature;
|
||||
pub mod feature_set;
|
||||
pub mod genesis_config;
|
||||
|
Reference in New Issue
Block a user