Salmon/Salmon.Core/Depth/Persistence.cs
2024-04-11 21:30:36 +02:00

36 lines
1.0 KiB
C#

namespace Salmon.Core.Depth;
public abstract class Persistence
{
/// <summary>
/// Must be thread safe
/// Must return immediately
/// </summary>
/// <param name="key">May not be null</param>
/// <param name="value"></param>
public virtual void PushStateChange(string subject, string predicate, object? value, DateTime when)
{
Task.Run(async () =>
{
try
{
var old = await GetLastValue(subject, predicate);
if(old != value)
await RegisterStateChange(subject, predicate, when, value);
}catch (Exception ex)
{
ExceptionCatched(ex);
}
}).ConfigureAwait(false);
}
public abstract Task<object> GetLastValue(string subject, string predicate);
protected abstract Task RegisterStateChange(string subject, string predicate, DateTime when, object? value);
protected virtual void ExceptionCatched(Exception e)
{
Console.WriteLine(e.ToString());
}
}