1
0

IOptimizedObservable.cs 770 B

123456789101112131415161718192021222324252627
  1. using System;
  2. namespace UniRx
  3. {
  4. public interface IOptimizedObservable<T> : IObservable<T>
  5. {
  6. bool IsRequiredSubscribeOnCurrentThread();
  7. }
  8. public static class OptimizedObservableExtensions
  9. {
  10. public static bool IsRequiredSubscribeOnCurrentThread<T>(this IObservable<T> source)
  11. {
  12. var obs = source as IOptimizedObservable<T>;
  13. if (obs == null) return true;
  14. return obs.IsRequiredSubscribeOnCurrentThread();
  15. }
  16. public static bool IsRequiredSubscribeOnCurrentThread<T>(this IObservable<T> source, IScheduler scheduler)
  17. {
  18. if (scheduler == Scheduler.CurrentThread) return true;
  19. return IsRequiredSubscribeOnCurrentThread(source);
  20. }
  21. }
  22. }