1
0

ImmediateScheduler.cs 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading;
  6. namespace UniRx
  7. {
  8. public static partial class Scheduler
  9. {
  10. public static readonly IScheduler Immediate = new ImmediateScheduler();
  11. class ImmediateScheduler : IScheduler
  12. {
  13. public ImmediateScheduler()
  14. {
  15. }
  16. public DateTimeOffset Now
  17. {
  18. get { return Scheduler.Now; }
  19. }
  20. public IDisposable Schedule(Action action)
  21. {
  22. action();
  23. return Disposable.Empty;
  24. }
  25. public IDisposable Schedule(TimeSpan dueTime, Action action)
  26. {
  27. var wait = Scheduler.Normalize(dueTime);
  28. if (wait.Ticks > 0)
  29. {
  30. Thread.Sleep(wait);
  31. }
  32. action();
  33. return Disposable.Empty;
  34. }
  35. }
  36. }
  37. }