private async Task <TResponse> SendRpcAsyncInternal <TResponse>(string cmd, object payload, BucketGroup group, int bucketId, ulong guildId, Optional <string> evt, bool ignoreState, RequestOptions options) where TResponse : class { if (!ignoreState) { CheckState(); } byte[] bytes = null; var guid = Guid.NewGuid(); payload = new API.Rpc.RpcMessage { Cmd = cmd, Event = evt, Args = payload, Nonce = guid }; if (payload != null) { var json = SerializeJson(payload); bytes = Encoding.UTF8.GetBytes(json); } var requestTracker = new RpcRequest <TResponse>(options); _requests[guid] = requestTracker; await _requestQueue.SendAsync(new WebSocketRequest(_webSocketClient, bytes, true, options), group, bucketId, guildId).ConfigureAwait(false); await _sentRpcMessageEvent.InvokeAsync(cmd).ConfigureAwait(false); return(await requestTracker.Promise.Task.ConfigureAwait(false)); }
private bool ProcessMessage(API.Rpc.RpcMessage msg) { RpcRequest requestTracker; if (_requests.TryGetValue(msg.Nonce.Value.Value, out requestTracker)) { if (msg.Event.GetValueOrDefault("") == "ERROR") { var _ = requestTracker.SetExceptionAsync(msg.Data.GetValueOrDefault() as JToken, _serializer); } else { var _ = requestTracker.SetResultAsync(msg.Data.GetValueOrDefault() as JToken, _serializer); } return(true); } else { return(false); } }