use std::{
sync::Arc,
time::Duration,
};
use qubit_function::{
BoxConsumer,
Consumer,
};
use qubit_progress::reporter::{
NoOpProgressReporter,
ProgressReporter,
};
use super::SequentialBatchProcessor;
pub struct SequentialBatchProcessorBuilder<Item> {
consumer: BoxConsumer<Item>,
report_interval: Duration,
reporter: Arc<dyn ProgressReporter>,
}
impl<Item> SequentialBatchProcessorBuilder<Item> {
#[inline]
pub fn new<C>(consumer: C) -> Self
where
C: Consumer<Item> + 'static,
{
Self {
consumer: consumer.into_box(),
report_interval: SequentialBatchProcessor::<Item>::DEFAULT_REPORT_INTERVAL,
reporter: Arc::new(NoOpProgressReporter),
}
}
#[inline]
pub const fn report_interval(mut self, report_interval: Duration) -> Self {
self.report_interval = report_interval;
self
}
#[inline]
pub fn reporter<R>(mut self, reporter: R) -> Self
where
R: ProgressReporter + 'static,
{
self.reporter = Arc::new(reporter);
self
}
#[inline]
pub fn reporter_arc(mut self, reporter: Arc<dyn ProgressReporter>) -> Self {
self.reporter = reporter;
self
}
#[inline]
pub fn no_reporter(mut self) -> Self {
self.reporter = Arc::new(NoOpProgressReporter);
self
}
#[inline]
pub fn build(self) -> SequentialBatchProcessor<Item> {
SequentialBatchProcessor {
consumer: self.consumer,
report_interval: self.report_interval,
reporter: self.reporter,
}
}
}