Port warn on drop from 0.9.x

This commit is contained in:
Aode (Lion) 2021-10-06 21:29:34 -05:00
parent c0ce6f303e
commit 461c9e5ed2

View file

@ -56,6 +56,19 @@ impl Worker for LocalWorkerHandle {
}
}
struct LogOnDrop<F>(F)
where
F: Fn() -> Span;
impl<F> Drop for LogOnDrop<F>
where
F: Fn() -> Span,
{
fn drop(&mut self) {
(self.0)().in_scope(|| info!("Worker closing"));
}
}
pub(crate) async fn local_worker<State>(
queue: String,
processors: CachedProcessorMap<State>,
@ -68,6 +81,8 @@ pub(crate) async fn local_worker<State>(
let handle = LocalWorkerHandle { tx, id, queue };
let log_on_drop = LogOnDrop(|| handle.span("closing"));
loop {
let span = handle.span("request");
if let Err(e) = server
@ -105,5 +120,5 @@ pub(crate) async fn local_worker<State>(
break;
}
handle.span("closing").in_scope(|| info!("Worker closing"));
drop(log_on_drop);
}