use std::{
num::NonZeroUsize,
sync::Arc,
time::Duration,
};
use qubit_progress::reporter::{
NoOpProgressReporter,
ProgressReporter,
};
use super::ChunkedBatchProcessor;
pub struct ChunkedBatchProcessorBuilder<P> {
delegate: P,
chunk_size: NonZeroUsize,
report_interval: Duration,
reporter: Arc<dyn ProgressReporter>,
}
impl<P> ChunkedBatchProcessorBuilder<P> {
#[inline]
pub fn new(delegate: P, chunk_size: NonZeroUsize) -> Self {
Self {
delegate,
chunk_size,
report_interval: ChunkedBatchProcessor::<P>::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) -> ChunkedBatchProcessor<P> {
ChunkedBatchProcessor {
delegate: self.delegate,
chunk_size: self.chunk_size,
report_interval: self.report_interval,
reporter: self.reporter,
}
}
}