src/source/multi/mod.rs

//! A [`Source`] that merges several underlying sources into one stream.
//!
//! Each child runs in its own `tokio::task` and pushes lines into a single
//! bounded channel consumed by the merger.

pub mod merger;

use anyhow::Result;
use tokio::sync::mpsc;

use super::{LineItem, Source};

pub struct MultiSource {
    rx: mpsc::Receiver<LineItem>,
    label: String,
}

impl MultiSource {
    pub fn new(rx: mpsc::Receiver<LineItem>, label: impl Into<String>) -> Self {
        Self {
            rx,
            label: label.into(),
        }
    }
}

#[async_trait::async_trait]
impl Source for MultiSource {
    async fn next_line(&mut self) -> Result<Option<LineItem>> {
        Ok(self.rx.recv().await)
    }

    fn label(&self) -> &str {
        &self.label
    }
}