/// <inheritdoc /> public async Task <DataPersisterUpdateResult <T> > Update(CancellationToken ct, DataPersisterUpdaterWithContext <T> updater) { using (await _updateGate.LockAsync(ct)) { var result = await _inner.Update(ct, updater); if (result.IsUpdated) { _update.OnNext(result); } return(result); } }
/// <inheritdoc /> public async Task <DataPersisterUpdateResult <T> > Update(CancellationToken ct, DataPersisterUpdaterWithContext <T> updater) { var innerUpdated = false; var result = await _inner.Update( ct, context => { innerUpdated = false; var adjustedContext = GetAdjustedReadResult(context); var innerContext = new DataPersisterTransactionContext <T>(adjustedContext); updater(innerContext); if (innerContext.IsCommitted) { innerUpdated = true; if (innerContext.IsRemoved) { context.RemoveAndCommit(); } else { var value = innerContext.CommittedValue; if (CheckMode(DefaultValueDataPersisterDecoratorMode.WriteCustomDefaultToEmpty) && _comparer.Equals(value, _customDefaultValue)) { context.RemoveAndCommit(); } else if (CheckMode(DefaultValueDataPersisterDecoratorMode.WriteDefaultToEmpty) && _comparer.Equals(value, default(T))) { context.RemoveAndCommit(); } else { context.Commit(value); } } } } ); var adjustedResult = GetAdjustedReadResult(result); return(new DataPersisterUpdateResult <T>(adjustedResult, innerUpdated || result.IsUpdated)); }