示例#1
0
        private async Task ReceiveAsync(MessageFrameReceiver messageFrameReceiver, CancellationToken cancellationToken)
        {
            var task         = messageFrameReceiver.ReceiveAsync(cancellationToken);
            var messageFrame = await task;

            _messageQueue.Add(messageFrame);
            MessageFrameReceived(messageFrame);

            var newTask = ReceiveAsync(messageFrameReceiver, cancellationToken);
        }
示例#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 ReceiveAsync(MessageFrameReceiver messageFrameReceiver, CancellationToken cancellationToken)
        {
            var task = messageFrameReceiver.ReceiveAsync(cancellationToken);
            var messageFrame = await task;
            _messageQueue.Add(messageFrame);
            MessageFrameReceived(messageFrame);

            var newTask = ReceiveAsync(messageFrameReceiver, cancellationToken);
        }