Files
2026-01-02 20:15:00 +02:00

24 lines
638 B
C#

using System.Core.Extensions;
namespace Daybreak.API.Models;
public sealed class ByteConsumerEntry(
Guid id, TimeSpan freq, Action<ReadOnlySpan<byte>> handler)
{
private readonly Action<ReadOnlySpan<byte>> handler = handler.ThrowIfNull();
private DateTime lastConsume = DateTime.MinValue;
public Guid Id { get; } = id;
public TimeSpan Frequency { get; } = freq;
public void TryConsume(DateTime currentTime, ReadOnlySpan<byte> value)
{
if (currentTime - this.lastConsume >= this.Frequency)
{
this.handler(value);
this.lastConsume = currentTime;
}
}
}