ResponseAwaiter.cs 674 B

1234567891011121314151617181920212223
  1. using GodotTools.IdeMessaging.Requests;
  2. using GodotTools.IdeMessaging.Utils;
  3. using Newtonsoft.Json;
  4. namespace GodotTools.IdeMessaging
  5. {
  6. public abstract class ResponseAwaiter : NotifyAwaiter<Response>
  7. {
  8. public abstract void SetResult(MessageContent content);
  9. }
  10. public class ResponseAwaiter<T> : ResponseAwaiter
  11. where T : Response, new()
  12. {
  13. public override void SetResult(MessageContent content)
  14. {
  15. if (content.Status == MessageStatus.Ok)
  16. SetResult(JsonConvert.DeserializeObject<T>(content.Body)!);
  17. else
  18. SetResult(new T { Status = content.Status });
  19. }
  20. }
  21. }