1
0

BinaryObserver.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. namespace System.Reactive
  3. {
  4. class BinaryObserver<TLeft, TRight> : IObserver<Either<Notification<TLeft>, Notification<TRight>>>
  5. {
  6. public BinaryObserver(IObserver<TLeft> leftObserver, IObserver<TRight> rightObserver)
  7. {
  8. LeftObserver = leftObserver;
  9. RightObserver = rightObserver;
  10. }
  11. public BinaryObserver(Action<Notification<TLeft>> left, Action<Notification<TRight>> right)
  12. : this(left.ToObserver(), right.ToObserver())
  13. {
  14. }
  15. public IObserver<TLeft> LeftObserver { get; private set; }
  16. public IObserver<TRight> RightObserver { get; private set; }
  17. void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnNext(Either<Notification<TLeft>, Notification<TRight>> value)
  18. {
  19. value.Switch(left => left.Accept(LeftObserver), right => right.Accept(RightObserver));
  20. }
  21. void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnError(Exception exception)
  22. {
  23. }
  24. void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnCompleted()
  25. {
  26. }
  27. }
  28. }