Skip to content
Frans Lytzen edited this page Oct 30, 2020 · 5 revisions

Documentation for use

There are two general ways to use this package.

SafeParallelAsync

Is a simple call that will run the provided Func over each of the items in the IEnumerable / IAsyncEnumerable without return any values and without any error handling. If you want error handling, you can either use a try/catch block in your Func or use the SafeParallelAsyncWithResult methods. The SafeParallelAsync methods are useful where the probability of errors is low and where you don't need the return the value. Writing messages to a queue is a good example; it's unlikely to go wrong and - if it does - you probably have bigger problems.

Example

IQueueWriter queueWriter = new FakeQueueWriter();
var enumerable = Enumerable.Range(1, 100).Select(i => $"Messsage {i}");

await enumerable.SafeParallelAsync(async msg => await queueWriter.Write(msg));

== SafeParallelAsyncWithResult == This will return an IAsyncEnumerable of an object which has the input value, any exception thrown and the output value (if the Func has a return value). Exceptions will be caught and will not interrupt processing. You should examine the result objects to check for exceptions and take appropriate action.

  • Chaining
  • Threading
  • Cancellation
Clone this wiki locally