private async Task <T> ExecuteSynchronousMessage <T>(BaseFayeMessage message, TimeSpan timeoutValue) where T : BaseFayeMessage { var json = Converter.Serialize(message); var tcs = new TaskCompletionSource <MessageReceivedArgs>(); _synchronousMessageEvents[message.Id] = tcs; _connection.Send(json); var task = tcs.Task; var result = await task.Timeout(timeoutValue); if (result == Result.Timeout) { var timeoutException = new TimeoutException(timeoutValue, json); _logger.ErrorException("Timeout problem, rethrowing", timeoutException); throw timeoutException; } _synchronousMessageEvents.Remove(message.Id); return(Converter.Deserialize <T>(task.Result.Message)); }
private async Task <T> ExecuteSynchronousMessage <T>(BaseFayeMessage message, TimeSpan timeoutValue) where T : BaseFayeMessage { var json = Converter.Serialize(message); var tcs = new TaskCompletionSource <MessageReceivedArgs>(); MessageReceived received = (sender, args) => tcs.SetResult(args); _transportConnection.MessageReceived += received; _transportConnection.Send(json); var task = tcs.Task; var result = await task.Timeout(timeoutValue); if (result == Result.Timeout) { var timeoutException = new TimeoutException(timeoutValue, json); _logger.ErrorException("Timeout problem, rethrowing", timeoutException); throw timeoutException; } var receivedString = task.Result.Message; _logger.Debug("Received message '{0}'", receivedString); _transportConnection.MessageReceived -= received; var array = JsonConvert.DeserializeObject <JArray>(receivedString); dynamic messageObj = array[0]; var newAdvice = ParseAdvice(messageObj); if (newAdvice != null) { _advice = newAdvice; SetRetry(_advice, _transportConnection); } return(Converter.Deserialize <T>(receivedString)); }