Пример #1
0
        private HttpContentClientStreamWriter <TRequest, TResponse> CreateWriter(HttpRequestMessage message)
        {
            _writeStreamTcs = new TaskCompletionSource <Stream>(TaskCreationOptions.RunContinuationsAsynchronously);
            _completeTcs    = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);

            message.Content = new PushStreamContent(
                (stream) =>
            {
                _writeStreamTcs.TrySetResult(stream);
                return(_completeTcs.Task);
            },
                GrpcProtocolConstants.GrpcContentTypeHeaderValue);

            var writer = new HttpContentClientStreamWriter <TRequest, TResponse>(this, _writeStreamTcs.Task, _completeTcs);

            return(writer);
        }
Пример #2
0
        private HttpContentClientStreamWriter <TRequest, TResponse> CreateWriter(HttpRequestMessage message)
        {
            var writeStreamTcs = new TaskCompletionSource <Stream>(TaskCreationOptions.RunContinuationsAsynchronously);
            var completeTcs    = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);

            // Canceling call will cancel pending writes to the stream
            _writerCtsRegistration = _callCts.Token.Register(() =>
            {
                completeTcs.TrySetCanceled();
                writeStreamTcs.TrySetCanceled();
            });

            message.Content = new PushStreamContent(
                (stream) =>
            {
                writeStreamTcs.TrySetResult(stream);
                return(completeTcs.Task);
            },
                GrpcProtocolConstants.GrpcContentTypeHeaderValue);

            var writer = new HttpContentClientStreamWriter <TRequest, TResponse>(this, writeStreamTcs.Task, completeTcs);

            return(writer);
        }