pub struct AsyncChecksumAdapter<T: ChecksumService + 'static> { /* private fields */ }Expand description
Async adapter for ChecksumService
Wraps a synchronous ChecksumService implementation and provides
async methods that execute the sync operations in a way that doesn’t
block the async runtime.
§Design Rationale
- Domain Purity: Domain traits remain sync and portable
- Infrastructure Flexibility: Async execution is an implementation detail
- Non-Blocking: Uses
spawn_blockingfor CPU-intensive operations - Zero-Cost When Sync: No overhead if used in sync contexts
Implementations§
Source§impl<T: ChecksumService + 'static> AsyncChecksumAdapter<T>
impl<T: ChecksumService + 'static> AsyncChecksumAdapter<T>
Sourcepub fn new(service: Arc<T>) -> Self
pub fn new(service: Arc<T>) -> Self
Creates a new async adapter wrapping a sync checksum service
Sourcepub async fn process_chunk_async(
&self,
chunk: FileChunk,
context: &mut ProcessingContext,
stage_name: &str,
) -> Result<FileChunk, PipelineError>
pub async fn process_chunk_async( &self, chunk: FileChunk, context: &mut ProcessingContext, stage_name: &str, ) -> Result<FileChunk, PipelineError>
Processes a chunk asynchronously, updating the running checksum
Executes the synchronous process operation in a blocking task pool to avoid blocking the async runtime.
Sourcepub async fn process_chunks_parallel(
&self,
chunks: Vec<FileChunk>,
context: &mut ProcessingContext,
stage_name: &str,
) -> Result<Vec<FileChunk>, PipelineError>
pub async fn process_chunks_parallel( &self, chunks: Vec<FileChunk>, context: &mut ProcessingContext, stage_name: &str, ) -> Result<Vec<FileChunk>, PipelineError>
Processes multiple chunks in parallel (infrastructure concern)
This method demonstrates how parallelization is an infrastructure concern, not a domain concern. The domain just defines process_chunk.
Sourcepub fn get_checksum(
&self,
context: &ProcessingContext,
stage_name: &str,
) -> Option<String>
pub fn get_checksum( &self, context: &ProcessingContext, stage_name: &str, ) -> Option<String>
Gets the final checksum value (sync operation)
Trait Implementations§
Source§impl<T: ChecksumService + 'static> Clone for AsyncChecksumAdapter<T>
impl<T: ChecksumService + 'static> Clone for AsyncChecksumAdapter<T>
Auto Trait Implementations§
impl<T> Freeze for AsyncChecksumAdapter<T>
impl<T> RefUnwindSafe for AsyncChecksumAdapter<T>where
T: RefUnwindSafe,
impl<T> Send for AsyncChecksumAdapter<T>
impl<T> Sync for AsyncChecksumAdapter<T>
impl<T> Unpin for AsyncChecksumAdapter<T>
impl<T> UnwindSafe for AsyncChecksumAdapter<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more