public void UnRegister(ICallConnection connection) { var toremove = new[] { connection }; while (true) { if (!_pool.TryGetValue(connection.Namespace, out var connections)) { return; } var newconnections = connections.Except(toremove).ToArray(); if (newconnections.Length == 0) { if (_pool.TryRemove(connection.Namespace, out var removed)) { foreach (var callConnection in removed.Except(toremove)) { Register(callConnection); } return; } continue; } if (_pool.TryUpdate(connection.Namespace, newconnections, connections)) { return; } } }
public void Register(ICallConnection connection) { _pool.AddOrUpdate(connection.Namespace, new[] { connection }, (s, connections) => connections.Concat(new[] { connection }).ToArray()); }