IgnoreElements.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if !NO_PERF
  3. using System;
  4. namespace System.Reactive.Linq.Observαble
  5. {
  6. 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> Ω()
  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. }
  45. #endif