Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <TResponse> Call(TRequest request, CancellationToken cancellationToken)
        {
            ThrowIfCompletedCall();

            var completionSource = new TaskCompletionSource <TResponse>();
            var callId           = ReverseCallId.New();

            while (!_calls.TryAdd(callId, completionSource))
            {
                callId = ReverseCallId.New();
            }

            try
            {
                await _writeSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);

                try
                {
                    var callContext = new ReverseCallRequestContext
                    {
                        CallId           = callId.ToProtobuf(),
                        ExecutionContext = _executionContextManager.Current.ToProtobuf(),
                    };
                    _setRequestContext(request, callContext);

                    var message = new TServerMessage();
                    _setMessageRequest(message, request);
                    _logger.Trace("Writing request with CallId: {CallId}", callId);
                    await _serverStream.WriteAsync(message).ConfigureAwait(false);
                }
                finally
                {
                    _writeSemaphore.Release();
                }

                return(await completionSource.Task.ConfigureAwait(false));
            }
            catch
            {
                _calls.TryRemove(callId, out _);
                throw;
            }
        }
Ejemplo n.º 2
0
 /// <inheritdoc/>
 public void SetRequestContext(ReverseCallRequestContext context, FilterEventRequest request)
 => request.CallContext = context;