コード例 #1
0
 private async Task SendMessageFrameAsync(IMessageFrameWriter writer, MessageFrame messageFrame, CancellationToken cancellationToken)
 {
     try
     {
         await writer.WriteMessageFrameAsync(messageFrame, cancellationToken);
     }
     catch
     {
         if (_resentMessageFrames.TryAdd(messageFrame))
         {
             Interlocked.Increment(ref _resentMessageFramesCount);
         }
         throw;
     }
 }
コード例 #2
0
        private async Task <IMessage> RequestWithCancellationToken(IMessage message, CancellationToken cancellationToken)
        {
            await _semaphoreRequest.WaitAsync(cancellationToken);

            try
            {
                var sendMessageFrame = _messageFrameCreator.CreateFromMessage(message);
                await _messageFrameWriter.WriteMessageFrameAsync(sendMessageFrame, cancellationToken);

                var messageFrame = await _messageFrameReceiver.ReceiveAsync(cancellationToken).ConfigureAwait(false);

                var responseMessage = _messageSerialization.Deserialize(messageFrame.MessageTypeId, messageFrame.RawMessage);
                return(responseMessage);
            }
            finally
            {
                _semaphoreRequest.Release();
            }
        }
コード例 #3
0
 private async Task SendMessageFrameAsync(IMessageFrameWriter writer, MessageFrame messageFrame, CancellationToken cancellationToken)
 {
     try
     {
         await writer.WriteMessageFrameAsync(messageFrame, cancellationToken);
     }
     catch
     {
         if (_resentMessageFrames.TryAdd(messageFrame))
         {
             Interlocked.Increment(ref _resentMessageFramesCount);
         }
         throw;
     }
 }