OnErrorResumeNext.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. using System.Collections.Generic;
  5. using System.Reactive.Concurrency;
  6. using System.Reactive.Disposables;
  7. namespace System.Reactive.Linq.Observαble
  8. {
  9. class OnErrorResumeNext<TSource> : Producer<TSource>
  10. {
  11. private readonly IEnumerable<IObservable<TSource>> _sources;
  12. public OnErrorResumeNext(IEnumerable<IObservable<TSource>> sources)
  13. {
  14. _sources = sources;
  15. }
  16. protected override IDisposable Run(IObserver<TSource> observer, IDisposable cancel, Action<IDisposable> setSink)
  17. {
  18. var sink = new _(observer, cancel);
  19. setSink(sink);
  20. return sink.Run(_sources);
  21. }
  22. class _ : TailRecursiveSink<TSource>
  23. {
  24. public _(IObserver<TSource> observer, IDisposable cancel)
  25. : base(observer, cancel)
  26. {
  27. }
  28. protected override IEnumerable<IObservable<TSource>> Extract(IObservable<TSource> source)
  29. {
  30. var oern = source as OnErrorResumeNext<TSource>;
  31. if (oern != null)
  32. return oern._sources;
  33. return null;
  34. }
  35. public override void OnNext(TSource value)
  36. {
  37. base._observer.OnNext(value);
  38. }
  39. public override void OnError(Exception error)
  40. {
  41. _recurse();
  42. }
  43. public override void OnCompleted()
  44. {
  45. _recurse();
  46. }
  47. }
  48. }
  49. }
  50. #endif