BinaryObserver.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System.Reactive
  5. {
  6. class BinaryObserver<TLeft, TRight> : IObserver<Either<Notification<TLeft>, Notification<TRight>>>
  7. {
  8. public BinaryObserver(IObserver<TLeft> leftObserver, IObserver<TRight> rightObserver)
  9. {
  10. LeftObserver = leftObserver;
  11. RightObserver = rightObserver;
  12. }
  13. public BinaryObserver(Action<Notification<TLeft>> left, Action<Notification<TRight>> right)
  14. : this(left.ToObserver(), right.ToObserver())
  15. {
  16. }
  17. public IObserver<TLeft> LeftObserver { get; private set; }
  18. public IObserver<TRight> RightObserver { get; private set; }
  19. void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnNext(Either<Notification<TLeft>, Notification<TRight>> value)
  20. {
  21. value.Switch(left => left.Accept(LeftObserver), right => right.Accept(RightObserver));
  22. }
  23. void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnError(Exception exception)
  24. {
  25. }
  26. void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnCompleted()
  27. {
  28. }
  29. }
  30. }