IgnoreElements.cs 1.3 KB

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