AsyncUtilities 0.5.0

There is a newer version of this package available.
See the version list below for details.
Install-Package AsyncUtilities -Version 0.5.0
dotnet add package AsyncUtilities --version 0.5.0
<PackageReference Include="AsyncUtilities" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AsyncUtilities --version 0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AsyncUtilities, 0.5.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install AsyncUtilities as a Cake Addin
#addin nuget:?package=AsyncUtilities&version=0.5.0

// Install AsyncUtilities as a Cake Tool
#tool nuget:?package=AsyncUtilities&version=0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AsyncUtilities

A collection of somewhat useful utilities for async programming:

Install

Install-Package AsyncUtilities

Usage

<a id="valueTask">ValueTask</a>

The non-generic ValueTask can be useful in async methods that are invoked very frequently, are likely to complete synchronously but unlike ValueTask<TResult> don't return a result. Usually these method will await another async method that does return a ValueTask<TResult>, for example:

async ValueTask DrawAsync(string name)
{
    var pen = await GetAsync<Pen>("pen");
    var apple = await Getsync<Apple>("apple");
    
    var applePen = pen.JamIn(apple);
    applePen.Draw();
}

async ValueTask<T> GetItemAsync<T>(string name)
{
    var item = GetFromCache<T>(name);
    if (item != null)
    {
        return item;
    }
    
    return await GetFromDbAsync<T>(name);
}

<a id="stripedasynclock">StripedAsyncLock</a>

StripedAsyncLock<TKey> can be used to reduce contention on an AsyncLock by dividing it into more granular stripes. This allows different operations to lock separate stripes concurrently instead of locking the entire lock altogether:

StripedAsyncLock<string> _lock = new StripedAsyncLock<string>(stripes: 100);
Cache _cache = new Cache();

async Task<T> GetOrCreateItem<T>(string name) where T : new()
{
    var item = _cache.Get<T>(name);
    if (item != null)
    {
        return item;
    }
    
    using (await _lock.LockAsync(name))
    {
        var item = _cache.Get<T>(name);
        if (item != null)
        {
            return item;
        }
        
        item = new T();
        _cache.Set(item;
        return item;
    }
}

License

AsyncUtilities is licensed under the MIT license.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 58 1/1/2022
1.0.1 154,880 7/12/2019
1.0.0 398 7/5/2019
0.6.1 92,879 12/9/2017
0.5.0 928 10/13/2017
0.4.0 876 7/14/2017
0.3.1 790 6/4/2017
0.3.0 747 6/3/2017
0.3.0-alpha 708 6/3/2017
0.2.0 797 6/2/2017
0.1.0 770 6/2/2017