Concat.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. using System.Collections.Generic;
  5. namespace System.Reactive.Linq.ObservableImpl
  6. {
  7. internal sealed class Concat<TSource> : Producer<TSource, Concat<TSource>._>, IConcatenatable<TSource>
  8. {
  9. private readonly IEnumerable<IObservable<TSource>> _sources;
  10. public Concat(IEnumerable<IObservable<TSource>> sources)
  11. {
  12. _sources = sources;
  13. }
  14. protected override _ CreateSink(IObserver<TSource> observer, IDisposable cancel) => new _(observer, cancel);
  15. protected override IDisposable Run(_ sink) => sink.Run(_sources);
  16. public IEnumerable<IObservable<TSource>> GetSources() => _sources;
  17. internal sealed class _ : ConcatSink<TSource>
  18. {
  19. public _(IObserver<TSource> observer, IDisposable cancel)
  20. : base(observer, cancel)
  21. {
  22. }
  23. public override void OnNext(TSource value)
  24. {
  25. base._observer.OnNext(value);
  26. }
  27. public override void OnError(Exception error)
  28. {
  29. base._observer.OnError(error);
  30. base.Dispose();
  31. }
  32. }
  33. }
  34. }