-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Documentation for use
There are two general ways to use this package.
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.
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