DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/NotificationSendingQueueService.cs
Степанов Дмитрий Александрович 96786b1be7 Сервисы для уведомлений
1. Добавил репозиторий для уведомлений
2. Добавил сервисы для уведомлений
2023-07-10 16:56:55 +05:00

42 lines
1.1 KiB
C#

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<NotificationDto> notificationsQueue = new();
public bool IsEmpty => notificationsQueue.IsEmpty;
public void Enqueue(NotificationDto notification)
{
notificationsQueue.Enqueue(notification);
manualResetEventSlim.Set();
}
public void EnqueueRange(IEnumerable<NotificationDto> 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();
}
}