Debian Codegraph @

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