use std::sync::Arc;
use tokio::sync::{RwLock, mpsc, oneshot};
use crate::pipeline::types::{PipelineInput, PipelineMetrics, PipelineOutput};
pub struct PipelineHandle {
pub input_tx: mpsc::Sender<PipelineInput>,
pub output_rx: mpsc::Receiver<PipelineOutput>,
pub metrics: Arc<RwLock<PipelineMetrics>>,
shutdown_tx: Option<oneshot::Sender<()>>,
}
impl PipelineHandle {
pub(crate) fn new(
input_tx: mpsc::Sender<PipelineInput>,
output_rx: mpsc::Receiver<PipelineOutput>,
metrics: Arc<RwLock<PipelineMetrics>>,
shutdown_tx: oneshot::Sender<()>,
) -> Self {
Self { input_tx, output_rx, metrics, shutdown_tx: Some(shutdown_tx) }
}
pub fn shutdown(&mut self) {
if let Some(tx) = self.shutdown_tx.take() {
let _ = tx.send(());
}
}
}