Class AsyncDataPipeline<T>
Provides async data pipeline operations with prefetching support.
public class AsyncDataPipeline<T> : IAsyncEnumerable<T>
Type Parameters
TThe type of data in the pipeline.
- Inheritance
-
AsyncDataPipeline<T>
- Implements
- Inherited Members
Methods
Batch(int, bool)
Groups elements into batches.
public AsyncDataPipeline<T[]> Batch(int batchSize, bool dropRemainder = false)
Parameters
batchSizeintNumber of elements per batch.
dropRemainderboolWhether to drop the last incomplete batch.
Returns
- AsyncDataPipeline<T[]>
A new AsyncDataPipeline of batched elements.
Filter(Func<T, bool>)
Filters elements based on a predicate.
public AsyncDataPipeline<T> Filter(Func<T, bool> predicate)
Parameters
Returns
- AsyncDataPipeline<T>
A new AsyncDataPipeline with filtered elements.
GetAsyncEnumerator(CancellationToken)
Returns an enumerator that iterates asynchronously through the collection.
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA CancellationToken that may be used to cancel the asynchronous iteration.
Returns
- IAsyncEnumerator<T>
An enumerator that can be used to iterate asynchronously through the collection.
MapAsync<TResult>(Func<T, CancellationToken, Task<TResult>>)
Applies an async transformation function to each element.
public AsyncDataPipeline<TResult> MapAsync<TResult>(Func<T, CancellationToken, Task<TResult>> selector)
Parameters
selectorFunc<T, CancellationToken, Task<TResult>>The async transformation function.
Returns
- AsyncDataPipeline<TResult>
A new AsyncDataPipeline with transformed elements.
Type Parameters
TResultThe type of the transformed elements.
Map<TResult>(Func<T, TResult>)
Applies a transformation function to each element.
public AsyncDataPipeline<TResult> Map<TResult>(Func<T, TResult> selector)
Parameters
selectorFunc<T, TResult>The transformation function.
Returns
- AsyncDataPipeline<TResult>
A new AsyncDataPipeline with transformed elements.
Type Parameters
TResultThe type of the transformed elements.
Prefetch(int)
Prefetches elements in the background for improved performance.
public AsyncDataPipeline<T> Prefetch(int bufferSize = 2)
Parameters
bufferSizeintNumber of elements to prefetch.
Returns
- AsyncDataPipeline<T>
A new AsyncDataPipeline with prefetching.
Take(int)
Takes only the first N elements.
public AsyncDataPipeline<T> Take(int count)
Parameters
countintNumber of elements to take.
Returns
- AsyncDataPipeline<T>
A new AsyncDataPipeline with limited elements.