IgnoreElements.cs 1.4 KB

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