// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. // See the LICENSE file in the project root for more information. using System.Reactive.Disposables; namespace System.Reactive.Linq.ObservableImpl { internal class AddRef : Producer._> { private readonly IObservable _source; private readonly RefCountDisposable _refCount; public AddRef(IObservable source, RefCountDisposable refCount) { _source = source; _refCount = refCount; } protected override _ CreateSink(IObserver observer) => new(observer, _refCount.GetDisposable()); protected override void Run(_ sink) => sink.Run(_source); internal sealed class _ : IdentitySink { private readonly IDisposable _refCountDisposable; public _(IObserver observer, IDisposable refCountDisposable) : base(observer) { _refCountDisposable = refCountDisposable; } protected override void Dispose(bool disposing) { if (disposing) { _refCountDisposable.Dispose(); } base.Dispose(disposing); } } } }