2023-02-07 15:21:00 +00:00
|
|
|
use futures_util::FutureExt;
|
|
|
|
use tokio::sync::oneshot::{channel, Sender};
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
2023-02-09 18:19:03 +00:00
|
|
|
pub mod http;
|
2023-02-04 01:01:49 +00:00
|
|
|
pub mod table;
|
2023-02-09 18:19:03 +00:00
|
|
|
pub mod telemetry;
|
2023-02-07 15:21:00 +00:00
|
|
|
|
|
|
|
pub struct Terminator {
|
|
|
|
signal: Sender<()>,
|
|
|
|
completion: JoinHandle<Result<()>>,
|
|
|
|
}
|
|
|
|
impl Terminator {
|
|
|
|
pub fn from_raw(signal: Sender<()>, completion: JoinHandle<Result<()>>) -> Terminator {
|
|
|
|
Terminator { signal, completion }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new(completion: JoinHandle<Result<()>>) -> (Terminator, impl Future<Output = ()>) {
|
|
|
|
let (signal, rx) = channel();
|
|
|
|
(Terminator { signal, completion }, rx.map(|_| ()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn terminate(self) -> Result<()> {
|
|
|
|
match self.signal.send(()) {
|
|
|
|
Ok(()) => {}
|
|
|
|
Err(_) => log::error!("Termination channel is dropped"),
|
|
|
|
}
|
|
|
|
self.completion.await??;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|