Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable/DoWhile.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 #if !NO_PERF
4 using System;
5 using System.Collections.Generic;
6
7 namespace System.Reactive.Linq.ObservableImpl
8 {
9 class DoWhile<TSource> : Producer<TSource>, IConcatenatable<TSource>
10 {
11 private readonly IObservable<TSource> _source;
12 private readonly Func<bool> _condition;
13
14 public DoWhile(IObservable<TSource> source, Func<bool> condition)
15 {
16 _condition = condition;
17 _source = source;
18 }
19
20 protected override IDisposable Run(IObserver<TSource> observer, IDisposable cancel, Action<IDisposable> setSink)
21 {
22 var sink = new _(observer, cancel);
23 setSink(sink);
24 return sink.Run(GetSources());
25 }
26
27 public IEnumerable<IObservable<TSource>> GetSources()
28 {
29 yield return _source;
30 while (_condition())
31 yield return _source;
32 }
33
34 class _ : ConcatSink<TSource>
35 {
36 public _(IObserver<TSource> observer, IDisposable cancel)
37 : base(observer, cancel)
38 {
39 }
40
41 public override void OnNext(TSource value)
42 {
43 base._observer.OnNext(value);
44 }
45
46 public override void OnError(Exception error)
47 {
48 base._observer.OnError(error);
49 base.Dispose();
50 }
51 }
52 }
53 }
54 #endif