Skip to main content

praxis_protocol/
cert_watcher_shutdowns.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2024 Praxis Contributors
3
4//! Shutdown handles for the TLS certificate hot-reload watchers.
5//!
6//! The server keeps a [`CertWatcherShutdowns`] for the process lifetime so the
7//! certificate watchers spawned during protocol registration can be stopped
8//! early if needed.
9
10use tokio::sync::watch;
11
12/// Collected TLS certificate watcher shutdown senders.
13///
14/// Background [`CertWatcher`] tasks run for the process lifetime. These
15/// [`watch::Sender`]s are held so a watcher can be asked to stop early via
16/// `send(true)`; dropping them does not stop the watchers (they end at process
17/// exit).
18///
19/// [`watch::Sender`]: tokio::sync::watch::Sender
20/// [`CertWatcher`]: praxis_tls::watcher::CertWatcher
21pub struct CertWatcherShutdowns {
22    /// Shutdown senders kept alive for the server lifetime.
23    _senders: Vec<watch::Sender<bool>>,
24}
25
26impl CertWatcherShutdowns {
27    /// Wrap collected shutdown senders.
28    pub fn new(senders: Vec<watch::Sender<bool>>) -> Self {
29        Self { _senders: senders }
30    }
31}