Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable/IsEmpty.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 IsEmpty<TSource> : Producer<bool>
9 {
10 private readonly IObservable<TSource> _source;
11
12 public IsEmpty(IObservable<TSource> source)
13 {
14 _source = source;
15 }
16
17 protected override IDisposable Run(IObserver<bool> observer, IDisposable cancel, Action<IDisposable> setSink)
18 {
19 var sink = new _(observer, cancel);
20 setSink(sink);
21 return _source.SubscribeSafe(sink);
22 }
23
24 class _ : Sink<bool>, IObserver<TSource>
25 {
26 public _(IObserver<bool> observer, IDisposable cancel)
27 : base(observer, cancel)
28 {
29 }
30
31 public void OnNext(TSource value)
32 {
33 base._observer.OnNext(false);
34 base._observer.OnCompleted();
35 base.Dispose();
36 }
37
38 public void OnError(Exception error)
39 {
40 base._observer.OnError(error);
41 base.Dispose();
42 }
43
44 public void OnCompleted()
45 {
46 base._observer.OnNext(true);
47 base._observer.OnCompleted();
48 base.Dispose();
49 }
50 }
51 }
52 }
53 #endif