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

github.com/mono/rx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Rx.NET/System.Reactive.Core/Reactive/Internal/SynchronizedObserver.cs')
-rw-r--r--Rx.NET/System.Reactive.Core/Reactive/Internal/SynchronizedObserver.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Rx.NET/System.Reactive.Core/Reactive/Internal/SynchronizedObserver.cs b/Rx.NET/System.Reactive.Core/Reactive/Internal/SynchronizedObserver.cs
new file mode 100644
index 0000000..e41294e
--- /dev/null
+++ b/Rx.NET/System.Reactive.Core/Reactive/Internal/SynchronizedObserver.cs
@@ -0,0 +1,40 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
+
+namespace System.Reactive
+{
+ internal class SynchronizedObserver<T> : ObserverBase<T>
+ {
+ private readonly object _gate;
+ private readonly IObserver<T> _observer;
+
+ public SynchronizedObserver(IObserver<T> observer, object gate)
+ {
+ _gate = gate;
+ _observer = observer;
+ }
+
+ protected override void OnNextCore(T value)
+ {
+ lock (_gate)
+ {
+ _observer.OnNext(value);
+ }
+ }
+
+ protected override void OnErrorCore(Exception exception)
+ {
+ lock (_gate)
+ {
+ _observer.OnError(exception);
+ }
+ }
+
+ protected override void OnCompletedCore()
+ {
+ lock (_gate)
+ {
+ _observer.OnCompleted();
+ }
+ }
+ }
+}