Concat.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.ObservableImpl
  8. {
  9. class Concat<TSource> : Producer<TSource>, IConcatenatable<TSource>
  10. {
  11. private readonly IEnumerable<IObservable<TSource>> _sources;
  12. public Concat(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. public IEnumerable<IObservable<TSource>> GetSources()
  23. {
  24. return _sources;
  25. }
  26. class _ : ConcatSink<TSource>
  27. {
  28. public _(IObserver<TSource> observer, IDisposable cancel)
  29. : base(observer, cancel)
  30. {
  31. }
  32. public override void OnNext(TSource value)
  33. {
  34. base._observer.OnNext(value);
  35. }
  36. public override void OnError(Exception error)
  37. {
  38. base._observer.OnError(error);
  39. base.Dispose();
  40. }
  41. }
  42. }
  43. }
  44. #endif