Example #1
0
        public void RemoveSubscriber(IMessageSubscriber subscriber)
        {
            lock (_syncRoot)
            {
                if (!_subscribers.Remove(subscriber))
                {
                    throw new InvalidOperationException($"Unknown subscriber {subscriber}");
                }

                subscriber.OnMessage("Good bye!");
            }
        }
Example #2
0
        public void RegisterSubscriber(IMessageSubscriber subscriber)
        {
            lock (_syncRoot)
            {
                if (!_subscribers.Add(subscriber))
                {
                    throw new InvalidOperationException($"Subscriber {subscriber} is already registered");
                }

                subscriber.OnMessage("Hello, new subscriber!");
            }
        }