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