Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Internal/PushPullAdapter.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_CDS || NO_PERF
4 using System.Collections.Generic;
5
6 namespace System.Reactive
7 {
8 sealed class PushPullAdapter<T, R> : IObserver<T>, IEnumerator<R>
9 {
10 Action<Notification<T>> yield;
11 Action dispose;
12 Func<Notification<R>> moveNext;
13 Notification<R> current;
14 bool done = false;
15 bool disposed;
16
17 public PushPullAdapter(Action<Notification<T>> yield, Func<Notification<R>> moveNext, Action dispose)
18 {
19 this.yield = yield;
20 this.moveNext = moveNext;
21 this.dispose = dispose;
22 }
23
24 public void OnNext(T value)
25 {
26 yield(Notification.CreateOnNext<T>(value));
27 }
28
29 public void OnError(Exception exception)
30 {
31 yield(Notification.CreateOnError<T>(exception));
32 dispose();
33 }
34
35 public void OnCompleted()
36 {
37 yield(Notification.CreateOnCompleted<T>());
38 dispose();
39 }
40
41 public R Current
42 {
43 get { return current.Value; }
44 }
45
46 public void Dispose()
47 {
48 disposed = true;
49 dispose();
50 }
51
52 object System.Collections.IEnumerator.Current
53 {
54 get { return this.Current; }
55 }
56
57 public bool MoveNext()
58 {
59 if (disposed)
60 throw new ObjectDisposedException("");
61
62 if (!done)
63 {
64 current = moveNext();
65 done = current.Kind != NotificationKind.OnNext;
66 }
67
68 current.Exception.ThrowIfNotNull();
69
70 return current.HasValue;
71 }
72
73 public void Reset()
74 {
75 throw new NotSupportedException();
76 }
77 }
78 }
79 #endif