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