SignalAwaiter.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. namespace Godot
  3. {
  4. public class SignalAwaiter : IAwaiter<object[]>, IAwaitable<object[]>
  5. {
  6. private bool completed;
  7. private object[] result;
  8. private Action action;
  9. public SignalAwaiter(Object source, string signal, Object target)
  10. {
  11. NativeCalls.godot_icall_Object_connect_signal_awaiter(
  12. Object.GetPtr(source),
  13. signal, Object.GetPtr(target), this
  14. );
  15. }
  16. public bool IsCompleted
  17. {
  18. get
  19. {
  20. return completed;
  21. }
  22. }
  23. public void OnCompleted(Action action)
  24. {
  25. this.action = action;
  26. }
  27. public object[] GetResult()
  28. {
  29. return result;
  30. }
  31. public IAwaiter<object[]> GetAwaiter()
  32. {
  33. return this;
  34. }
  35. internal void SignalCallback(object[] args)
  36. {
  37. completed = true;
  38. result = args;
  39. if (action != null)
  40. {
  41. action();
  42. }
  43. }
  44. internal void FailureCallback()
  45. {
  46. action = null;
  47. completed = true;
  48. }
  49. }
  50. }