Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PushPullAdapter.cs « Internal « Reactive « System.Reactive.Linq « Source « NET « Rx - github.com/mono/rx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5804538a521d686627310d8b7bf1f305ce58a555 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

#if NO_CDS || NO_PERF
using System.Collections.Generic;

namespace System.Reactive
{
    sealed class PushPullAdapter<T, R> : IObserver<T>, IEnumerator<R>
    {
        Action<Notification<T>> yield;
        Action dispose;
        Func<Notification<R>> moveNext;
        Notification<R> current;
        bool done = false;
        bool disposed;

        public PushPullAdapter(Action<Notification<T>> yield, Func<Notification<R>> moveNext, Action dispose)
        {
            this.yield = yield;
            this.moveNext = moveNext;
            this.dispose = dispose;
        }

        public void OnNext(T value)
        {
            yield(Notification.CreateOnNext<T>(value));
        }

        public void OnError(Exception exception)
        {
            yield(Notification.CreateOnError<T>(exception));
            dispose();
        }

        public void OnCompleted()
        {
            yield(Notification.CreateOnCompleted<T>());
            dispose();
        }

        public R Current
        {
            get { return current.Value; }
        }

        public void Dispose()
        {
            disposed = true;
            dispose();
        }

        object System.Collections.IEnumerator.Current
        {
            get { return this.Current; }
        }

        public bool MoveNext()
        {
            if (disposed)
                throw new ObjectDisposedException("");

            if (!done)
            {
                current = moveNext();
                done = current.Kind != NotificationKind.OnNext;
            }

            current.Exception.ThrowIfNotNull();

            return current.HasValue;
        }

        public void Reset()
        {
            throw new NotSupportedException();
        }
    }
}
#endif