| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
using System.Reactive.Concurrency; |
| 4 |
|
| 5 |
namespace System.Reactive |
| 6 |
{ |
| 7 |
internal class AsyncLockObserver<T> : ObserverBase<T> |
| 8 |
{ |
| 9 |
private readonly AsyncLock _gate; |
| 10 |
private readonly IObserver<T> _observer; |
| 11 |
|
| 12 |
public AsyncLockObserver(IObserver<T> observer, AsyncLock gate) |
| 13 |
{ |
| 14 |
_gate = gate; |
| 15 |
_observer = observer; |
| 16 |
} |
| 17 |
|
| 18 |
protected override void OnNextCore(T value) |
| 19 |
{ |
| 20 |
_gate.Wait(() => |
| 21 |
{ |
| 22 |
_observer.OnNext(value); |
| 23 |
}); |
| 24 |
} |
| 25 |
|
| 26 |
protected override void OnErrorCore(Exception exception) |
| 27 |
{ |
| 28 |
_gate.Wait(() => |
| 29 |
{ |
| 30 |
_observer.OnError(exception); |
| 31 |
}); |
| 32 |
} |
| 33 |
|
| 34 |
protected override void OnCompletedCore() |
| 35 |
{ |
| 36 |
_gate.Wait(() => |
| 37 |
{ |
| 38 |
_observer.OnCompleted(); |
| 39 |
}); |
| 40 |
} |
| 41 |
} |
| 42 |
} |