/// <summary> /// Remove 'subscription from the list of subscriptions that the observable has. Called when /// subscriptions are disposed. Returns true if the subscription was removed. /// </summary> private bool Remove(AllListenerSubscription subscription) { lock (s_allListenersLock) { if (_subscriptions == subscription) { _subscriptions = subscription.Next; return(true); } else if (_subscriptions != null) { for (var cur = _subscriptions; cur.Next != null; cur = cur.Next) { if (cur.Next == subscription) { cur.Next = cur.Next.Next; return(true); } } } // Subscriber likely disposed multiple times return(false); } }
public IDisposable Subscribe(IObserver <DiagnosticListener> observer) { lock (s_allListenersLock) { // Call back for each existing listener on the new callback (catch-up). for (DiagnosticListener cur = s_allListeners; cur != null; cur = cur._next) { observer.OnNext(cur); } // Add the observer to the list of subscribers. _subscriptions = new AllListenerSubscription(this, observer, _subscriptions); return(_subscriptions); } }
/// <summary> /// Remove 'subscription from the list of subscriptions that the observable has. Called when /// subscriptions are disposed. /// </summary> private void Remove(AllListenerSubscription subscription) { lock (DefaultListener) { // Remove myself from the linked list. if (_subscriptions == subscription) { _subscriptions = subscription.Next; } else { for (var cur = _subscriptions; cur.Next != null; cur = cur.Next) { if (cur.Next.Subscriber == this) { cur.Next = cur.Next.Next; return; } } Debug.Assert(false, "Could not find subscription in the AllListeners subscribers list"); } } }
internal AllListenerSubscription(AllListenerObservable owner, IObserver <DiagnosticListener> subscriber, AllListenerSubscription next) { this._owner = owner; this.Subscriber = subscriber; this.Next = next; }