/// <summary> /// Gets the contract from the meta service. /// </summary> /// <param name="key"></param> /// <returns></returns> private EmitterContract FetchContract(int key) { try { Service.Logger.Log("Fetch contract #" + key); // Query the meta service var response = Query.Get("/v1/contract/" + key, 10000); if (response != null) { // Deserialize the response as JSON return(JsonConvert.DeserializeObject <EmitterContract>(response)); } Service.Logger.Log(LogLevel.Error, "Unable to fetch contract #" + key); return(null); } catch (Exception ex) { Service.Logger.Log(ex); return(null); } }
private static IEnumerator <float> MakeRequest(string url, Action <ThreadSafeRequest> errorHandler, Action <string> resultHandler) { ThreadSafeRequest request = new ThreadSafeRequest(); Task.Run(() => { request.Result = HttpQuery.Get(url, out bool success, out HttpStatusCode code); request.Success = success; request.Code = code; request.done = true; }); yield return(Timing.WaitUntilTrue(() => request.done)); if (request.Success) { resultHandler(request.Result); } else { errorHandler(request); } }