fix init bug

feed
Avril 4 years ago
parent 5ba673e64f
commit 4e1e38a0fd
Signed by: flanchan
GPG Key ID: 284488987C31F630

2
Cargo.lock generated

@ -616,7 +616,7 @@ dependencies = [
[[package]]
name = "markov"
version = "0.7.1"
version = "0.7.2"
dependencies = [
"async-compression",
"bzip2-sys",

@ -43,6 +43,9 @@ hog-buffer = []
# Enable the /api/ route
api = []
# Do not wait 2 seconds before starting worker tasks after server
instant-init = []
[profile.release]
opt-level = 3
lto = "fat"

@ -281,8 +281,15 @@ async fn main() {
tokio::join![
server,
async move {
trace!("Init set");
init.set().expect("Failed to initialise saver")
cfg_if! {
if #[cfg(feature="instant-init")] {
trace!("Setting init");
} else {
trace!("Setting init in 2 seconds for good measure.");
tokio::time::delay_for(tokio::time::Duration::from_secs(2)).await;
}
}
init.set().expect("Failed to initialise saver")
},
];
}).await;
@ -290,7 +297,8 @@ async fn main() {
// Cleanup
async move {
trace!("Cleanup");
debug!("Waiting on {} tasks now", tasks.len());
join_all(tasks).await;
}
}.await;

@ -68,9 +68,10 @@ impl Initialiser
pub async fn wait(&mut self) -> Result<(), InitWaitError>
{
if !*self.rx.borrow() {
self.rx.recv().await
.ok_or_else(|| InitWaitError)
.and_then(|x| if x {Ok(())} else {Err(InitWaitError)})
while !self.rx.recv().await.ok_or_else(|| InitWaitError)? {
tokio::task::yield_now().await;
}
Ok(())
} else {
Ok(())
}
@ -95,14 +96,8 @@ impl Future for Initialiser
{
type Output = Result<(), InitWaitError>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !*self.rx.borrow() {
let rx = self.rx.recv();
tokio::pin!(rx);
rx.poll(cx).map(|x| x.ok_or_else(|| InitWaitError)
.and_then(|x| if x {Ok(())} else {Err(InitWaitError)}))
} else {
Poll::Ready(Ok(()))
}
let uhh = self.wait();
tokio::pin!(uhh);
uhh.poll(cx)
}
}

@ -58,9 +58,7 @@ impl State
pub async fn on_init_save(&mut self) -> Result<(), ShutdownError>
{
tokio::select!{
Ok(()) = self.save_begin.wait() => {
Ok(())
}
Ok(()) = self.save_begin.wait() => Ok(()),
Some(true) = self.shutdown_recv.recv() => {
debug!("on_init_save(): shutdown received");
Err(ShutdownError)

Loading…
Cancel
Save