pub struct SequentialBatchProcessor<Item> { /* private fields */ }Expand description
Processes batch items sequentially by invoking a Consumer per item.
The processor stores the supplied consumer as a BoxConsumer and invokes it
on the caller thread in input order. Consumer panics are not caught; they
propagate to the caller and no BatchProcessResult is produced. Progress
updates are emitted only between items.
§Type Parameters
Item- Item type consumed by the stored consumer.
use qubit_batch::{
BatchProcessor,
SequentialBatchProcessor,
};
let mut processor = SequentialBatchProcessor::new(|item: &i32| {
assert!(*item > 0);
});
let result = processor
.process([1, 2, 3])
.expect("array length should be exact");
assert!(result.is_success());Implementations§
Source§impl<Item> SequentialBatchProcessor<Item>
impl<Item> SequentialBatchProcessor<Item>
Sourcepub const DEFAULT_REPORT_INTERVAL: Duration
pub const DEFAULT_REPORT_INTERVAL: Duration
Default interval between progress callbacks.
Sourcepub fn new<C>(consumer: C) -> Selfwhere
C: Consumer<Item> + 'static,
pub fn new<C>(consumer: C) -> Selfwhere
C: Consumer<Item> + 'static,
Creates a sequential consumer-backed batch processor.
§Parameters
consumer- Consumer invoked once for each input item.
§Returns
A processor storing consumer as a BoxConsumer.
Sourcepub fn builder<C>(consumer: C) -> SequentialBatchProcessorBuilder<Item>where
C: Consumer<Item> + 'static,
pub fn builder<C>(consumer: C) -> SequentialBatchProcessorBuilder<Item>where
C: Consumer<Item> + 'static,
Sourcepub const fn report_interval(&self) -> Duration
pub const fn report_interval(&self) -> Duration
Returns the configured progress-report interval.
§Returns
The minimum time between due-based running progress callbacks.
Sourcepub fn reporter(&self) -> &Arc<dyn ProgressReporter>
pub fn reporter(&self) -> &Arc<dyn ProgressReporter>
Returns the configured progress reporter.
§Returns
A shared reference to the configured progress reporter.
Sourcepub const fn consumer(&self) -> &BoxConsumer<Item>
pub const fn consumer(&self) -> &BoxConsumer<Item>
Sourcepub fn into_consumer(self) -> BoxConsumer<Item>
pub fn into_consumer(self) -> BoxConsumer<Item>
Consumes this processor and returns the stored consumer.
§Returns
The boxed consumer used by this processor.
Trait Implementations§
Source§impl<Item> BatchProcessor<Item> for SequentialBatchProcessor<Item>
impl<Item> BatchProcessor<Item> for SequentialBatchProcessor<Item>
Source§fn process_with_count<I>(
&mut self,
items: I,
count: usize,
) -> Result<BatchProcessResult, Self::Error>where
I: IntoIterator<Item = Item>,
fn process_with_count<I>(
&mut self,
items: I,
count: usize,
) -> Result<BatchProcessResult, Self::Error>where
I: IntoIterator<Item = Item>,
Processes items sequentially on the caller thread.
§Parameters
items- Item source for the batch.count- Declared number of items expected fromitems.
§Returns
A result with completed and processed counts equal to the number of
consumer calls when the input source yields exactly count items.
§Errors
Returns BatchProcessError::CountShortfall when the source ends before
count, or BatchProcessError::CountExceeded when the source yields an
extra item. Extra items are observed but not passed to the consumer.
§Panics
Propagates any panic raised by the stored consumer or the configured progress reporter.