// 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.Concurrency; using System.Reactive.Disposables; namespace System.Reactive.Linq.ObservableImpl { internal sealed class Empty : Producer._> { private readonly IScheduler _scheduler; public Empty(IScheduler scheduler) { _scheduler = scheduler; } protected override _ CreateSink(IObserver observer) => new(observer); protected override void Run(_ sink) => sink.Run(_scheduler); internal sealed class _ : IdentitySink { public _(IObserver observer) : base(observer) { } public void Run(IScheduler scheduler) { SetUpstream(scheduler.ScheduleAction(this, static target => target.OnCompleted())); } } } internal sealed class EmptyDirect : BasicProducer { internal static readonly IObservable Instance = new EmptyDirect(); private EmptyDirect() { } protected override IDisposable Run(IObserver observer) { observer.OnCompleted(); return Disposable.Empty; } } }