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 _tasks = new BlockingCollection(); // 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; } } }