DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/ReportsBackgroundQueue.cs
2021-09-27 11:47:39 +05:00

29 lines
743 B
C#

using AsbCloudApp.Services;
using System;
using System.Collections.Concurrent;
namespace AsbCloudInfrastructure.Services
{
class ReportsBackgroundQueue : IReportsBackgroundQueue
{
private readonly ConcurrentQueue<(Action<int> action, int id)> tasks =
new ConcurrentQueue<(Action<int> action, int id)>();
private int id = 0;
public int EnqueueTask(Action<int> action)
{
if (action == null)
throw new ArgumentNullException(nameof(action));
id++;
tasks.Enqueue(new(action, id));
return id;
}
public bool TryDequeue(out (Action<int> action, int id) item)
=> tasks.TryDequeue(out item);
}
}