using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using AsbCloudApp.Data; using AsbCloudApp.Services; namespace AsbCloudInfrastructure.Services; public class NotificationSendingQueueService : INotificationSendingQueueService { private readonly ManualResetEventSlim manualResetEventSlim = new(); private readonly ConcurrentQueue notificationsQueue = new(); public bool IsEmpty => notificationsQueue.IsEmpty; public void Enqueue(NotificationDto notification) { notificationsQueue.Enqueue(notification); manualResetEventSlim.Set(); } public void EnqueueRange(IEnumerable notifications) { foreach (var notification in notifications) { notificationsQueue.Enqueue(notification); } manualResetEventSlim.Set(); } public bool TryDequeue(out NotificationDto notification) { return notificationsQueue.TryDequeue(out notification!); } public void Wait(CancellationToken cancellationToken) { manualResetEventSlim.Wait(cancellationToken); manualResetEventSlim.Reset(); } }