forked from ddrilling/AsbCloudServer
29 lines
743 B
C#
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);
|
|
}
|
|
}
|