DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/BackgroundQueue.cs

27 lines
683 B
C#
Raw Normal View History

using System;
using System.Collections.Concurrent;
using AsbCloudApp.Services;
namespace AsbCloudInfrastructure.Services
{
class BackgroundQueue : IBackgroundQueue
{
private 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);
}
}