|
|
|
@ -28,7 +28,7 @@ pub struct State
|
|
|
|
|
exclude: Arc<(sanitise::filter::Filter, sanitise::filter::Filter)>,
|
|
|
|
|
chain: Arc<RwLock<Chain<String>>>,
|
|
|
|
|
save: Arc<Notify>,
|
|
|
|
|
save_begin: Initialiser,
|
|
|
|
|
begin: Initialiser,
|
|
|
|
|
|
|
|
|
|
shutdown: Arc<watch::Sender<bool>>,
|
|
|
|
|
shutdown_recv: watch::Receiver<bool>,
|
|
|
|
@ -37,30 +37,34 @@ pub struct State
|
|
|
|
|
impl State
|
|
|
|
|
{
|
|
|
|
|
/// Consume this `state` into its initialiser
|
|
|
|
|
pub fn into_save_initialiser(self) -> Initialiser
|
|
|
|
|
pub fn into_initialiser(self) -> Initialiser
|
|
|
|
|
{
|
|
|
|
|
self.save_begin
|
|
|
|
|
self.begin
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Allow the saver task to start work
|
|
|
|
|
pub fn init_save(self) -> Result<(), msg::InitError>
|
|
|
|
|
pub fn init(self) -> Result<(), msg::InitError>
|
|
|
|
|
{
|
|
|
|
|
self.save_begin.set()
|
|
|
|
|
self.begin.set()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Has `init_save` been called?
|
|
|
|
|
pub fn is_init_save(&self) -> bool
|
|
|
|
|
/// Has `init` been called?
|
|
|
|
|
pub fn is_init(&self) -> bool
|
|
|
|
|
{
|
|
|
|
|
self.save_begin.is_set()
|
|
|
|
|
self.begin.is_set()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A future that completes either when `init_save` is called, or `shutdown`.
|
|
|
|
|
pub async fn on_init_save(&mut self) -> Result<(), ShutdownError>
|
|
|
|
|
/// A future that completes either when `init` is called, or `shutdown`.
|
|
|
|
|
pub async fn on_init(&mut self) -> Result<(), ShutdownError>
|
|
|
|
|
{
|
|
|
|
|
tokio::select!{
|
|
|
|
|
Ok(()) = self.save_begin.wait() => Ok(()),
|
|
|
|
|
Some(true) = self.shutdown_recv.recv() => {
|
|
|
|
|
debug!("on_init_save(): shutdown received");
|
|
|
|
|
if self.has_shutdown() {
|
|
|
|
|
return Err(ShutdownError);
|
|
|
|
|
}
|
|
|
|
|
let mut begin = self.begin.clone();
|
|
|
|
|
tokio::select!{ //fuck
|
|
|
|
|
Ok(()) = begin.wait() => Ok(()),
|
|
|
|
|
_ = self.on_shutdown() => {
|
|
|
|
|
debug!("on_init(): shutdown received");
|
|
|
|
|
Err(ShutdownError)
|
|
|
|
|
}
|
|
|
|
|
else => Err(ShutdownError)
|
|
|
|
@ -85,7 +89,7 @@ impl State
|
|
|
|
|
config: Arc::new(config),
|
|
|
|
|
chain,
|
|
|
|
|
save,
|
|
|
|
|
save_begin: Initialiser::new(),
|
|
|
|
|
begin: Initialiser::new(),
|
|
|
|
|
shutdown: Arc::new(shutdown),
|
|
|
|
|
shutdown_recv,
|
|
|
|
|
}
|
|
|
|
|