Debian Codegraph @

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