Multi-Threaded Processor (Scatter Gather)
Multi-Threaded Processor
Multi-Threaded Processor allows you to efficiently process data in parallel across multiple threads, using both simple and advanced approaches for scatter-gather operations.
Unlike a traditional "scatter-gather", MTP allows you to separate the loading and processing across threads and then await the results. This is incredibly powerful when the loading is done from a remote source where latency is involved.
An Example
SDK
ParallelProcessMultiThread
Processes a collection of items in parallel using a specified processing function.
Parameters:
items
(IEnumerable<TIn>
): The collection of items to process.Process
(Func<TIn, TOut>
): The function to process each item.cancelToken
(CancellationToken?
, optional): An optional cancellation token to cancel the processing.concurrency
(int
, optional): The number of concurrent threads to use. Default is 3.Logger
(ILogger
, optional): An optional logger for logging.
Returns:
List<MultiProcessResult<TIn, TOut>>
: A list of processing results.
Example:
Enqueue
Enqueue an item to be processed.
Parameters:
item
(TIn
): The item to be processed.
Example:
AwaitProcessed
Await until all pending executions have been processed. Optionally accepts a cancellation token or a time span to limit the wait.
Example:
Class Reference
MultiProcessResult<TIn, TOut>
A class that represents the result of processing an individual item.
InData
The input data that was processed.
OutData
The output data produced by the process.
Exception
An optional exception that occurred during processing.
ProcessTime
An optional timespan representing the processing time.
Last updated