using AsyncAwaitBestPractices;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Core.Models.Settings;
///
/// Transaction object which saves settings manager changes when disposed.
///
public class SettingsTransaction : IDisposable, IAsyncDisposable
{
private readonly ISettingsManager settingsManager;
private readonly Func onCommit;
public Settings Settings => settingsManager.Settings;
public SettingsTransaction(ISettingsManager settingsManager, Func onCommit)
{
this.settingsManager = settingsManager;
this.onCommit = onCommit;
}
public void Dispose()
{
onCommit().SafeFireAndForget();
GC.SuppressFinalize(this);
}
public async ValueTask DisposeAsync()
{
await onCommit();
GC.SuppressFinalize(this);
}
}