use std::sync::Arc;
pub struct ServeHandle {
pub(super) join: tokio::task::JoinHandle<()>,
pub(super) shutdown_notify: Arc<tokio::sync::Notify>,
pub(super) drain_timeout: std::time::Duration,
pub(super) done_rx: tokio::sync::watch::Receiver<bool>,
}
impl ServeHandle {
pub fn shutdown(&self) {
self.shutdown_notify.notify_one();
}
pub async fn drain(self) {
self.shutdown();
let _ = self.join.await;
}
pub fn abort(&self) {
self.join.abort();
}
pub fn drain_timeout(&self) -> std::time::Duration {
self.drain_timeout
}
pub fn subscribe_done(&self) -> tokio::sync::watch::Receiver<bool> {
self.done_rx.clone()
}
}