IgnoreElements.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using UniRx.Operators;
  3. namespace UniRx.Operators
  4. {
  5. internal class IgnoreElementsObservable<T> : OperatorObservableBase<T>
  6. {
  7. readonly IObservable<T> source;
  8. public IgnoreElementsObservable(IObservable<T> source)
  9. : base(source.IsRequiredSubscribeOnCurrentThread())
  10. {
  11. this.source = source;
  12. }
  13. protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
  14. {
  15. return source.Subscribe(new IgnoreElements(observer, cancel));
  16. }
  17. class IgnoreElements : OperatorObserverBase<T, T>
  18. {
  19. public IgnoreElements(IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
  20. {
  21. }
  22. public override void OnNext(T value)
  23. {
  24. }
  25. public override void OnError(Exception error)
  26. {
  27. try { observer.OnError(error); }
  28. finally { Dispose(); }
  29. }
  30. public override void OnCompleted()
  31. {
  32. try { observer.OnCompleted(); }
  33. finally { Dispose(); }
  34. }
  35. }
  36. }
  37. }