2021-05-19 14:41:27 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
|
|
|
|
|
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)>();
|
2021-05-19 14:41:27 +05:00
|
|
|
|
|
|
|
|
|
private int id = 0;
|
|
|
|
|
|
2021-05-20 12:38:25 +05:00
|
|
|
|
public int EnqueueTask(Action<int> action)
|
2021-05-19 14:41:27 +05:00
|
|
|
|
{
|
|
|
|
|
if (action == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(action));
|
|
|
|
|
|
2021-06-07 16:31:14 +05:00
|
|
|
|
id++;
|
|
|
|
|
|
|
|
|
|
tasks.Enqueue(new(action, id));
|
2021-05-19 14:41:27 +05:00
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 12:38:25 +05:00
|
|
|
|
public bool TryDequeue(out (Action<int> action, int id) item)
|
2021-05-19 14:41:27 +05:00
|
|
|
|
=> tasks.TryDequeue(out item);
|
|
|
|
|
}
|
|
|
|
|
}
|