Fix logic error and upgrade warn to panic in debug

This commit is contained in:
Félix Saparelli 2021-09-28 23:44:28 +13:00
parent 6b306a15ab
commit 45a7ce6aa0
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 12 additions and 5 deletions

View File

@ -13,7 +13,7 @@ use tokio::{
}, },
task::JoinHandle, task::JoinHandle,
}; };
use tracing::{debug, error, trace, warn}; use tracing::{debug, error, trace};
use crate::{ use crate::{
error::RuntimeError, error::RuntimeError,
@ -192,12 +192,19 @@ impl Supervisor {
.map_err(|err| RuntimeError::InternalSupervisor(err.to_string()))?; .map_err(|err| RuntimeError::InternalSupervisor(err.to_string()))?;
debug!("supervisor completed"); debug!("supervisor completed");
if !self.ongoing.swap(false, Ordering::SeqCst) { if self.ongoing.swap(false, Ordering::SeqCst) {
warn!("oneshot completed but ongoing was true, this should never happen"); #[cfg(debug_assertions)]
panic!("oneshot completed but ongoing was true, this should never happen");
#[cfg(not(debug_assertions))]
tracing::warn!("oneshot completed but ongoing was true, this should never happen");
} }
} else { } else {
warn!("waiter is None but ongoing was true, this should never happen"); #[cfg(debug_assertions)]
self.ongoing.store(false, Ordering::SeqCst); panic!("waiter is None but ongoing was true, this should never happen");
#[cfg(not(debug_assertions))] {
self.ongoing.store(false, Ordering::SeqCst);
tracing::warn!("waiter is None but ongoing was true, this should never happen");
}
} }
Ok(()) Ok(())