Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
        /// <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));
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
        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);