using System.Threading.Channels; using Microsoft.Extensions.Logging; namespace CompServ.Hub { public class HubWorkerHolder(ILogger logger) { internal readonly List<(string url, int ratio)> Workers = new(); internal readonly Channel Queue1 = Channel.CreateBounded(1); public void RegisterWorker(string url, int ratio) { logger.LogInformation($"Register worker: {url} with ratio {ratio}"); lock (Workers) { if (Workers.Any(p => p.url == url)) return; Workers.Add((url, ratio)); } } public void UnRegisterWorker(string url) { logger.LogInformation($"Un Register worker: {url}"); lock (Workers) { var found = Workers.FirstOrDefault(p => p.url == url); if (found != default) Workers.Remove(found); } } public async Task GetWorkerAsync() { var url = await Queue1.Reader.ReadAsync(); logger.LogInformation($"Assign worker: {url}"); return url; } } }