IgnoreElements.cs 1.4 KB

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