Adding
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
namespace LCU.Shared.Collections.RepoApiLib.Hosted
|
||||
{
|
||||
/**
|
||||
* Should be injected as a singleton. Can be used by a controller to queue something.
|
||||
*/
|
||||
public class HostedTaskQueue : IHostedTaskQueue
|
||||
{
|
||||
private readonly BlockingCollection<TaskSettings> _tasks = new BlockingCollection<TaskSettings>();
|
||||
|
||||
// This will not block.
|
||||
public void Enqueue(TaskSettings settings)
|
||||
{
|
||||
_tasks.Add(settings);
|
||||
}
|
||||
|
||||
// This will block.
|
||||
public TaskSettings Dequeue(CancellationToken token)
|
||||
{
|
||||
return _tasks.Take(token);
|
||||
}
|
||||
|
||||
public int GetCount()
|
||||
{
|
||||
return _tasks.Count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user