public async Task <bool> TryUpdateAsync(ITransaction tx, TKey key, TValue newValue, TValue comparisonValue, TimeSpan timeout, CancellationToken cancellationToken) { // We can't trust that comparisonValue is exactly equal to the old value, so we have to read the precise old value first. var current = await _dictionary.TryGetValueAsync(tx, key, LockMode.Update, timeout, cancellationToken).ConfigureAwait(false); if (!current.HasValue) { return(false); } var result = await _dictionary.TryUpdateAsync(tx, key, newValue, comparisonValue, timeout, cancellationToken).ConfigureAwait(false); if (result) { await OnUpdateAsync(tx, key, current.Value, newValue, timeout, cancellationToken).ConfigureAwait(false); } return(result); }