Class ConcurrentDictionaryExtensions
Extensions used to manage asynchronous access to the ImageSharpMiddleware https://gist.github.com/davidfowl/3dac8f7b3d141ae87abf770d5781feed
Inherited Members
Namespace: SixLabors.ImageSharp.Web.Middleware
Assembly: SixLabors.ImageSharp.Web.dll
Syntax
public static class ConcurrentDictionaryExtensions
Methods
| Improve this Doc View SourceGetOrAddAsync<TKey, TValue>(ConcurrentDictionary<TKey, Task<TValue>>, TKey, Func<TKey, Task<TValue>>)
Provides an alternative to GetOrAdd(TKey, Func<TKey,TValue>) specifically for asynchronous values. The factory method will only run once.
Declaration
public static async Task<TValue> GetOrAddAsync<TKey, TValue>(this ConcurrentDictionary<TKey, Task<TValue>> dictionary, TKey key, Func<TKey, Task<TValue>> valueFactory)
Parameters
Type | Name | Description |
---|---|---|
ConcurrentDictionary<TKey, Task<TValue>> | dictionary | |
TKey | key | The key of the element to add. |
Func<TKey, Task<TValue>> | valueFactory | The function used to generate a value for the key |
Returns
Type | Description |
---|---|
Task<TValue> | The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value for the key as returned by valueFactory if the key was not in the dictionary. |
Type Parameters
Name | Description |
---|---|
TKey | The type of the key. |
TValue | The value for the dictionary. |