/// <inheritdoc />
        public void Register(ISignalReceiver listener)
        {
            RemovePendingRemovals();

            _sources.Add(listener);
            _node = _node.GetOrCreateChildNodeFor(listener.RegisteredTypeId);

            if (_node.Registry.ListenerCount != _sources.Count)
            {
                Debug.Log("Something when wrong");
            }

            System.Diagnostics.Debug.Assert(_node.Registry.ListenerCount == _sources.Count);
        }
        /// <summary> Removes listeners that were marked for removal. </summary>
        private void RemovePendingRemovals()
        {
            if (!_isPendingRemoval)
            {
                return;
            }

            _isPendingRemoval = false;

            CachedListeners.Clear();
            CachedListeners.AddRange(_sources);

            _node = _node.GetRootNode();
            _sources.Clear();

            // re-register of the old registers that isn't the one that we're looking for
            foreach (var oldListener in CachedListeners)
            {
                if (oldListener != null)
                {
                    Register(oldListener);
                }
            }
        }
 /// <summary> Constructor. </summary>
 /// <param name="tree"> The tree for which this signal broadcaster is valid. </param>
 public SignalBroadcaster(SignalRegistryTree tree)
 {
     _node    = tree.Root;
     _sources = new List <ISignalReceiver>();
 }
 /// <inheritdoc />
 public void Dispose()
 {
     _sources.Clear();
     _node = null;
 }