You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
671 B
26 lines
671 B
using AsyncAwaitBestPractices; |
|
using StabilityMatrix.Core.Services; |
|
|
|
namespace StabilityMatrix.Core.Models.Settings; |
|
|
|
/// <summary> |
|
/// Transaction object which saves settings manager changes when disposed. |
|
/// </summary> |
|
public class SettingsTransaction(ISettingsManager settingsManager, Func<Task> onCommit) |
|
: IDisposable, |
|
IAsyncDisposable |
|
{ |
|
public Settings Settings => settingsManager.Settings; |
|
|
|
public void Dispose() |
|
{ |
|
onCommit().SafeFireAndForget(); |
|
GC.SuppressFinalize(this); |
|
} |
|
|
|
public async ValueTask DisposeAsync() |
|
{ |
|
await onCommit().ConfigureAwait(false); |
|
GC.SuppressFinalize(this); |
|
} |
|
}
|
|
|