DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/BackgroundQueue.cs
2021-05-19 15:21:19 +05:00

27 lines
692 B
C#

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