using System; using System.Threading; namespace UniRx.Operators { public abstract class OperatorObserverBase : IDisposable, IObserver { protected internal volatile IObserver observer; IDisposable cancel; public OperatorObserverBase(IObserver observer, IDisposable cancel) { this.observer = observer; this.cancel = cancel; } public abstract void OnNext(TSource value); public abstract void OnError(Exception error); public abstract void OnCompleted(); public void Dispose() { observer = UniRx.InternalUtil.EmptyObserver.Instance; var target = System.Threading.Interlocked.Exchange(ref cancel, null); if (target != null) { target.Dispose(); } } } }