IgnoreElements.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #if !NO_PERF
  5. using System;
  6. namespace System.Reactive.Linq.ObservableImpl
  7. {
  8. class IgnoreElements<TSource> : Producer<TSource>
  9. {
  10. private readonly IObservable<TSource> _source;
  11. public IgnoreElements(IObservable<TSource> source)
  12. {
  13. _source = source;
  14. }
  15. public IObservable<TSource> Omega()
  16. {
  17. return this;
  18. }
  19. protected override IDisposable Run(IObserver<TSource> observer, IDisposable cancel, Action<IDisposable> setSink)
  20. {
  21. var sink = new _(observer, cancel);
  22. setSink(sink);
  23. return _source.SubscribeSafe(sink);
  24. }
  25. class _ : Sink<TSource>, IObserver<TSource>
  26. {
  27. public _(IObserver<TSource> observer, IDisposable cancel)
  28. : base(observer, cancel)
  29. {
  30. }
  31. public void OnNext(TSource value)
  32. {
  33. }
  34. public void OnError(Exception error)
  35. {
  36. base._observer.OnError(error);
  37. base.Dispose();
  38. }
  39. public void OnCompleted()
  40. {
  41. base._observer.OnCompleted();
  42. base.Dispose();
  43. }
  44. }
  45. }
  46. }
  47. #endif