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