Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable/Do.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 Do<TSource> : Producer<TSource>
9 {
10 private readonly IObservable<TSource> _source;
11 private readonly Action<TSource> _onNext;
12 private readonly Action<Exception> _onError;
13 private readonly Action _onCompleted;
14
15 public Do(IObservable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)
16 {
17 _source = source;
18 _onNext = onNext;
19 _onError = onError;
20 _onCompleted = onCompleted;
21 }
22
23 protected override IDisposable Run(IObserver<TSource> observer, IDisposable cancel, Action<IDisposable> setSink)
24 {
25 var sink = new _(this, observer, cancel);
26 setSink(sink);
27 return _source.SubscribeSafe(sink);
28 }
29
30 class _ : Sink<TSource>, IObserver<TSource>
31 {
32 private readonly Do<TSource> _parent;
33
34 public _(Do<TSource> parent, IObserver<TSource> observer, IDisposable cancel)
35 : base(observer, cancel)
36 {
37 _parent = parent;
38 }
39
40 public void OnNext(TSource value)
41 {
42 try
43 {
44 _parent._onNext(value);
45 }
46 catch (Exception ex)
47 {
48 base._observer.OnError(ex);
49 base.Dispose();
50 return;
51 }
52
53 base._observer.OnNext(value);
54 }
55
56 public void OnError(Exception error)
57 {
58 try
59 {
60 _parent._onError(error);
61 }
62 catch (Exception ex)
63 {
64 base._observer.OnError(ex);
65 base.Dispose();
66 return;
67 }
68
69 base._observer.OnError(error);
70 base.Dispose();
71 }
72
73 public void OnCompleted()
74 {
75 try
76 {
77 _parent._onCompleted();
78 }
79 catch (Exception ex)
80 {
81 base._observer.OnError(ex);
82 base.Dispose();
83 return;
84 }
85
86 base._observer.OnCompleted();
87 base.Dispose();
88 }
89 }
90 }
91 }
92 #endif