/// <summary> /// Checks if the key exists and the value exists in the set. /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TItem">The type of the item.</typeparam> /// <param name="setMap">The set map.</param> /// <param name="key">The key.</param> /// <param name="item">The item.</param> /// <returns></returns> public static async Task <bool> ContainsItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap, TKey key, TItem item) { var set = await setMap.GetValueOrEmptyAsync(key).ConfigureAwait(false); return(await set.ContainsAsync(item).ConfigureAwait(false)); }
/// <summary> /// Checks if the key exists and the value exists in the set. /// </summary> public static async Task <bool> ContainsItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap, TKey key, TItem item, CancellationToken cancellationToken = default) { var set = await setMap.GetValueOrEmptyAsync(key, cancellationToken).ConfigureAwait(false); return(await set.ContainsAsync(item, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Adds an item to the set. /// If the key doesn't exists, it will be created. /// If the value already exists, it is overwritten. /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TItem">The type of the item.</typeparam> /// <param name="setMap">The set map.</param> /// <param name="key">The key.</param> /// <param name="item">The item.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task AddItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap, TKey key, TItem item, CancellationToken cancellationToken = default) { var set = await setMap.GetValueOrEmptyAsync(key, cancellationToken).ConfigureAwait(false); await set.AddAsync(item, cancellationToken).ConfigureAwait(false); }
/// <summary> /// Adds some items to the set. /// If the key doesn't exists, it will be created. /// If the value already exists, it is overwritten. /// </summary> public static async Task AddItemsAsync <TKey, TItem>( this ISetMap <TKey, TItem> setMap, TKey key, IAsyncEnumerable <TItem> items, CancellationToken cancellationToken = default) { var set = await setMap.GetValueOrEmptyAsync(key, cancellationToken).ConfigureAwait(false); await set.AddRangeAsync(items, cancellationToken).ConfigureAwait(false); }
/// <summary> /// Adds an item to the set. /// If the key doesn't exists, it will be created. /// If the value already exists, it is overwritten. /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TItem">The type of the item.</typeparam> /// <param name="setMap">The set map.</param> /// <param name="key">The key.</param> /// <param name="item">The item.</param> /// <returns></returns> public static async Task AddItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap, TKey key, TItem item) { var set = await setMap.GetValueOrEmptyAsync(key).ConfigureAwait(false); await set.AddAsync(item).ConfigureAwait(false); }
public async Task <ISet <TValue> > GetValueOrEmptyAsync(TKey key, CancellationToken cancellationToken = default) { var set = await _setMap.GetValueOrEmptyAsync(key, cancellationToken).ConfigureAwait(false); return(new NotifyWriteSet <TValue>(set, (_, token) => _writeHandler(key, token))); }
public Task <ISet <TValue> > GetValueOrEmptyAsync(TKey key, CancellationToken cancellationToken = default) => _underlyingSetMap.GetValueOrEmptyAsync(key, cancellationToken);