use tokio::sync::mpsc::Receiver;

use crate::chopper::types::Row;
use crate::sink::sink::Sink;

pub struct SinkDriver {
    rx: Receiver<Box<Row>>,
    sink: Box<dyn Sink>,
}

impl SinkDriver {
    pub fn new(rx: Receiver<Box<Row>>, sink: Box<dyn Sink>) -> SinkDriver {
        SinkDriver { sink, rx }
    }

    pub async fn run(&mut self) {
        while let Some(row) = self.rx.recv().await {
            self.sink.write(row).unwrap();
        }
    }
}
