Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable/All.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
6 namespace System.Reactive.Linq.ObservableImpl
7 {
8 class All<TSource> : Producer<bool>
9 {
10 private readonly IObservable<TSource> _source;
11 private readonly Func<TSource, bool> _predicate;
12
13 public All(IObservable<TSource> source, Func<TSource, bool> predicate)
14 {
15 _source = source;
16 _predicate = predicate;
17 }
18
19 protected override IDisposable Run(IObserver<bool> observer, IDisposable cancel, Action<IDisposable> setSink)
20 {
21 var sink = new _(this, observer, cancel);
22 setSink(sink);
23 return _source.SubscribeSafe(sink);
24 }
25
26 class _ : Sink<bool>, IObserver<TSource>
27 {
28 private readonly All<TSource> _parent;
29
30 public _(All<TSource> parent, IObserver<bool> observer, IDisposable cancel)
31 : base(observer, cancel)
32 {
33 _parent = parent;
34 }
35
36 public void OnNext(TSource value)
37 {
38 var res = false;
39 try
40 {
41 res = _parent._predicate(value);
42 }
43 catch (Exception ex)
44 {
45 base._observer.OnError(ex);
46 base.Dispose();
47 return;
48 }
49
50 if (!res)
51 {
52 base._observer.OnNext(false);
53 base._observer.OnCompleted();
54 base.Dispose();
55 }
56 }
57
58 public void OnError(Exception error)
59 {
60 base._observer.OnError(error);
61 base.Dispose();
62 }
63
64 public void OnCompleted()
65 {
66 base._observer.OnNext(true);
67 base._observer.OnCompleted();
68 base.Dispose();
69 }
70 }
71 }
72 }
73 #endif