IsEmpty.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System.Reactive.Linq.ObservableImpl
  5. {
  6. internal sealed class IsEmpty<TSource> : Producer<bool, IsEmpty<TSource>._>
  7. {
  8. private readonly IObservable<TSource> _source;
  9. public IsEmpty(IObservable<TSource> source)
  10. {
  11. _source = source;
  12. }
  13. protected override _ CreateSink(IObserver<bool> observer) => new _(observer);
  14. protected override void Run(_ sink) => sink.Run(_source);
  15. internal sealed class _ : Sink<TSource, bool>
  16. {
  17. public _(IObserver<bool> observer)
  18. : base(observer)
  19. {
  20. }
  21. public override void OnNext(TSource value)
  22. {
  23. ForwardOnNext(false);
  24. ForwardOnCompleted();
  25. }
  26. public override void OnCompleted()
  27. {
  28. ForwardOnNext(true);
  29. ForwardOnCompleted();
  30. }
  31. }
  32. }
  33. }