The 'async8' library is a utility package designed to simplify asynchronous programming in .NET applications. It offers a comprehensive set of tools, including extension methods for Task-based operations, concurrent task management helpers, async-enabled caching, and robust retry policies. These features help developers write clean, efficient, and maintainable asynchronous code, reducing complexity while improving scalability and performance.
$ dotnet add package async8A utility library for simplifying asynchronous programming in .NET.
Run multiple tasks concurrently with a specified degree of parallelism.
using Async8.Helpers;
var items = Enumerable.Range(1, 100);
await ConcurrentHelpers.ParallelForEachAsync(items, degreeOfParallelism: 4, async item =>
{
await ProcessItemAsync(item);
});
Cache the results of asynchronous operations to avoid redundant computations.
using Async8.Caching;
var cache = new AsyncCache<string, string>();
var value = await cache.GetOrAddAsync("key1", async key =>
{
return await FetchDataAsync(key);
});
Handle transient errors by automatically retrying failed operations.
using Async8.Policies;
var result = await RetryPolicy.ExecuteWithRetryAsync(async () =>
{
return await ExternalServiceCallAsync();
}, maxRetries: 3, delayBetweenRetries: TimeSpan.FromSeconds(2));
Handle transient errors by automatically retrying failed operations.
using Async8.Extensions;
var result = await SomeAsyncMethod().WithTimeout(TimeSpan.FromSeconds(5));