2
0

SynchronizedObserver.cs 804 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace UniRx.Operators
  3. {
  4. internal class SynchronizedObserver<T> : IObserver<T>
  5. {
  6. readonly IObserver<T> observer;
  7. readonly object gate;
  8. public SynchronizedObserver(IObserver<T> observer, object gate)
  9. {
  10. this.observer = observer;
  11. this.gate = gate;
  12. }
  13. public void OnNext(T value)
  14. {
  15. lock (gate)
  16. {
  17. observer.OnNext(value);
  18. }
  19. }
  20. public void OnError(Exception error)
  21. {
  22. lock (gate)
  23. {
  24. observer.OnError(error);
  25. }
  26. }
  27. public void OnCompleted()
  28. {
  29. lock (gate)
  30. {
  31. observer.OnCompleted();
  32. }
  33. }
  34. }
  35. }