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

29 lines
729 B
C#
Raw Normal View History

2021-07-21 15:29:19 +05:00
using AsbCloudApp.Services;
using System;
using System.Collections.Concurrent;
namespace AsbCloudInfrastructure.Services
{
class BackgroundQueue : IBackgroundQueue
{
2021-05-20 12:38:25 +05:00
private readonly ConcurrentQueue<(Action<int> action, int id)> tasks =
new ConcurrentQueue<(Action<int> action, int id)>();
private int id = 0;
2021-05-20 12:38:25 +05:00
public int EnqueueTask(Action<int> action)
{
if (action == null)
throw new ArgumentNullException(nameof(action));
id++;
tasks.Enqueue(new(action, id));
return id;
}
2021-05-20 12:38:25 +05:00
public bool TryDequeue(out (Action<int> action, int id) item)
=> tasks.TryDequeue(out item);
}
}