1
0

Concat.cs 1.5 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. #if !NO_PERF
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Reactive.Concurrency;
  8. using System.Reactive.Disposables;
  9. namespace System.Reactive.Linq.ObservableImpl
  10. {
  11. class Concat<TSource> : Producer<TSource>, IConcatenatable<TSource>
  12. {
  13. private readonly IEnumerable<IObservable<TSource>> _sources;
  14. public Concat(IEnumerable<IObservable<TSource>> sources)
  15. {
  16. _sources = sources;
  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 sink.Run(_sources);
  23. }
  24. public IEnumerable<IObservable<TSource>> GetSources()
  25. {
  26. return _sources;
  27. }
  28. class _ : ConcatSink<TSource>
  29. {
  30. public _(IObserver<TSource> observer, IDisposable cancel)
  31. : base(observer, cancel)
  32. {
  33. }
  34. public override void OnNext(TSource value)
  35. {
  36. base._observer.OnNext(value);
  37. }
  38. public override void OnError(Exception error)
  39. {
  40. base._observer.OnError(error);
  41. base.Dispose();
  42. }
  43. }
  44. }
  45. }
  46. #endif