using System.Collections.Concurrent;
namespace SharedLibraryCore.Helpers
{
///
/// This class provides a way to keep track of changes to an entity
///
/// Type of entity to keep track of changes to
public class ChangeTracking
{
private readonly ConcurrentQueue Values;
public ChangeTracking()
{
Values = new ConcurrentQueue();
}
public bool HasChanges => Values.Count > 0;
public void OnChange(T value)
{
if (Values.Count > 30)
{
Values.TryDequeue(out var throwAway);
}
Values.Enqueue(value);
}
public T GetNextChange()
{
var itemDequeued = Values.TryDequeue(out var val);
return itemDequeued ? val : default;
}
}
}