Skip to main content

ParallelBatchProcessorBuilder

Struct ParallelBatchProcessorBuilder 

Source
pub struct ParallelBatchProcessorBuilder<Item> { /* private fields */ }
Expand description

Builder for ParallelBatchProcessor.

Use the builder when the default worker count, sequential fallback threshold, progress interval, or reporter should be customized.

use qubit_batch::ParallelBatchProcessor;

let processor = ParallelBatchProcessor::builder(|_item: &i32| {})
    .thread_count(2)
    .sequential_threshold(0)
    .build()
    .expect("parallel processor configuration should be valid");

assert_eq!(processor.thread_count(), 2);
assert_eq!(processor.sequential_threshold(), 0);

Implementations§

Source§

impl<Item> ParallelBatchProcessorBuilder<Item>

Source

pub fn new<C>(consumer: C) -> Self
where C: Consumer<Item> + Send + Sync + 'static,

Creates a builder from a thread-safe consumer.

§Parameters
  • consumer - Thread-safe consumer invoked once for each accepted item.
§Returns

A builder initialized with default parallel processor settings.

Source

pub const fn thread_count(self, thread_count: usize) -> Self

Sets the worker-thread count.

§Parameters
  • thread_count - Number of scoped worker threads to use.
§Returns

This builder for fluent configuration.

Source

pub const fn sequential_threshold(self, sequential_threshold: usize) -> Self

Sets the sequential fallback threshold.

§Parameters
  • sequential_threshold - Maximum declared item count that still runs on the caller thread. Use 0 when every non-empty batch should use scoped workers.
§Returns

This builder for fluent configuration.

Source

pub const fn report_interval(self, report_interval: Duration) -> Self

Sets the progress-report interval.

§Parameters
  • report_interval - Minimum time between due-based running progress callbacks. Duration::ZERO reports at every sequential between-item progress point or on parallel worker completion signals without periodic polling.
§Returns

This builder for fluent configuration.

Source

pub fn reporter<R>(self, reporter: R) -> Self
where R: ProgressReporter + 'static,

Sets the progress reporter used by built processors.

§Parameters
  • reporter - Progress reporter used for later processing calls.
§Returns

This builder for fluent configuration.

Source

pub fn reporter_arc(self, reporter: Arc<dyn ProgressReporter>) -> Self

Sets the shared progress reporter used by built processors.

§Parameters
  • reporter - Shared progress reporter used for later processing calls.
§Returns

This builder for fluent configuration.

Source

pub fn no_reporter(self) -> Self

Disables progress callbacks by using NoOpProgressReporter.

§Returns

This builder for fluent configuration.

Source

pub fn build( self, ) -> Result<ParallelBatchProcessor<Item>, ParallelBatchProcessorBuildError>

Builds a validated ParallelBatchProcessor.

§Returns

A parallel batch processor when the configuration is valid.

§Errors

Returns ParallelBatchProcessorBuildError when the worker count is zero.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.