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]] [[package]]
name = "markov" name = "markov"
version = "0.7.1" version = "0.7.2"
dependencies = [ dependencies = [
"async-compression", "async-compression",
"bzip2-sys", "bzip2-sys",

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

@ -281,8 +281,15 @@ async fn main() {
tokio::join![ tokio::join![
server, server,
async move { async move {
trace!("Init set"); cfg_if! {
init.set().expect("Failed to initialise saver") 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; }).await;
@ -290,7 +297,8 @@ async fn main() {
// Cleanup // Cleanup
async move { async move {
trace!("Cleanup"); trace!("Cleanup");
debug!("Waiting on {} tasks now", tasks.len());
join_all(tasks).await; join_all(tasks).await;
} }
}.await; }.await;

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

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

Loading…
Cancel
Save