예제 #1
0
        internal void Unsubscribe(ChannelSubscriptionBase <T> subscription)
        {
            Guard.ArgumentNotNull(subscription, "subscription");

            lock (_instanceLock)
            {
                var _subscribers = _subscriptions.ToArray();

                foreach (var _subscriber in _subscribers)
                {
                    if (_subscriber.Subscriber == null)
                    {
                        _subscriptions.Remove(_subscriber);
                    }

                    else if (Object.ReferenceEquals(_subscriber, subscription))
                    {
                        _subscriptions.Remove(_subscriber);
                    }
                }
            }
        }
예제 #2
0
        private IDisposable OnSubscribeInternal(IObserver <T> subscriber, ThreadOption threadOption, bool useWeakReference)
        {
            Guard.ArgumentNotNull(subscriber, "subscriber");

            ChannelSubscriptionBase <T> _subscription = null;

            if (useWeakReference)
            {
                _subscription = new WeakChannelSubscription <T>(threadOption, subscriber);
            }
            else
            {
                _subscription = new ChannelSubscription <T>(threadOption, subscriber);
            }

            lock (_instanceLock)
            {
                // we add it to our collection
                _subscriptions.Add(_subscription);
            }

            // we return
            return(_subscription);
        }