public async Task <TValue> AddOrUpdateAsync(ITransaction tx, TKey key, Func <TKey, TValue> addValueFactory, Func <TKey, TValue, TValue> updateValueFactory, TimeSpan timeout, CancellationToken cancellationToken) { bool isAdd = false; TValue value = default(TValue); TValue oldValue = default(TValue); var result = await _dictionary.AddOrUpdateAsync( tx, key, k => { isAdd = true; value = addValueFactory(k); return(value); }, (k, v) => { isAdd = false; oldValue = v; value = updateValueFactory(k, v); return(value); }, timeout, cancellationToken).ConfigureAwait(false); if (isAdd) { await OnAddAsync(tx, key, value, timeout, cancellationToken).ConfigureAwait(false); } else { await OnUpdateAsync(tx, key, oldValue, value, timeout, cancellationToken).ConfigureAwait(false); } return(result); }
private async Task AddAsync(ITransaction tx, TKey key, IEnumerable <string> words, TimeSpan timeout, CancellationToken token) { foreach (var word in words) { await _index.AddOrUpdateAsync(tx, word, f => new[] { key }, (f, keys) => keys.CopyAndAdd(key), timeout, token).ConfigureAwait(false); } }
private Task AddAsync(ITransaction tx, TKey key, TFilter filter, TimeSpan timeout, CancellationToken token) { return(_index.AddOrUpdateAsync(tx, filter, f => new[] { key }, (f, keys) => keys.CopyAndAdd(key), timeout, token)); }