private async Task SendWebSocketRequestAsync(GraphQLWebSocketRequest request)
        {
            try
            {
                if (_internalCancellationToken.IsCancellationRequested)
                {
                    request.SendCanceled();
                    return;
                }

                await InitializeWebSocket();

                var requestBytes = _client.JsonSerializer.SerializeToBytes(request);
                await _clientWebSocket.SendAsync(
                    new ArraySegment <byte>(requestBytes),
                    WebSocketMessageType.Text,
                    true,
                    _internalCancellationToken);

                request.SendCompleted();
            }
            catch (Exception e)
            {
                request.SendFailed(e);
            }
        }
Пример #2
0
        private async Task<Unit> SendWebSocketRequestAsync(GraphQLWebSocketRequest request)
        {
            try
            {
                if (_internalCancellationToken.IsCancellationRequested)
                {
                    request.SendCanceled();
                    return Unit.Default;
                }

                await InitializeWebSocket();
                await SendWebSocketMessageAsync(request, _internalCancellationToken);
                request.SendCompleted();
            }
            catch (Exception e)
            {
                request.SendFailed(e);
            }
            return Unit.Default;
        }
        private async Task _sendWebSocketRequest(GraphQLWebSocketRequest request)
        {
            try {
                if (cancellationTokenSource.Token.IsCancellationRequested)
                {
                    request.SendCanceled();
                    return;
                }

                await InitializeWebSocket().ConfigureAwait(false);

                var requestBytes = Options.JsonSerializer.SerializeToBytes(request);
                await this.clientWebSocket.SendAsync(
                    new ArraySegment <byte>(requestBytes),
                    WebSocketMessageType.Text,
                    true,
                    cancellationTokenSource.Token).ConfigureAwait(false);

                request.SendCompleted();
            }
            catch (Exception e) {
                request.SendFailed(e);
            }
        }