public void Send(RpcPayload payload) { if (!_runCts.IsCancellationRequested) { _sendQueue?.Add(payload); } }
private void HandleEvent(RpcPayload evnt, TaskCompletionSource <bool> readySignal) { if (evnt.Event == RpcEvent.Error) { var data = evnt.Data as ErrorEvent; throw new WumpusRpcException(data.Code, data.Message); } switch (evnt.Command) { case RpcCommand.Authenticate: readySignal.SetResult(true); break; } }
private async Task SendAsync(ClientWebSocket client, CancellationToken cancelToken, RpcPayload payload) { payload.Nonce = Guid.NewGuid(); var writer = JsonSerializer.Write(payload); await client.SendAsync(writer.AsSegment(), WebSocketMessageType.Text, true, cancelToken); SentPayload?.Invoke(payload, new PayloadInfo(writer.Length, writer.Length)); }