Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable/While.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 While<TSource> : Producer<TSource>, IConcatenatable<TSource>
10 {
11 private readonly Func<bool> _condition;
12 private readonly IObservable<TSource> _source;
13
14 public While(Func<bool> condition, IObservable<TSource> source)
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 while (_condition())
30 yield return _source;
31 }
32
33 class _ : ConcatSink<TSource>
34 {
35 public _(IObserver<TSource> observer, IDisposable cancel)
36 : base(observer, cancel)
37 {
38 }
39
40 public override void OnNext(TSource value)
41 {
42 base._observer.OnNext(value);
43 }
44
45 public override void OnError(Exception error)
46 {
47 base._observer.OnError(error);
48 base.Dispose();
49 }
50 }
51 }
52 }
53 #endif