protected override void ProcessResponse(RESPObject response)
        {
            if (response == null)
            {
                if (_current != null)
                {
                    _current.SetCancelled();
                    _current = null;
                }

                return;
            }

            if (_current == null && !_pending.TryDequeue(out _current))
            {
                throw new InvalidOperationException("Received command response but no token available.");
            }

            try
            {
                HandleResponseWithToken(response);
            }
            catch (OperationCanceledException)
            {
                _current.SetCancelled();
                throw;
            }
            catch (Exception ex)
            {
                _current.SetFaulted(ex);
                throw;
            }
        }
Exemplo n.º 2
0
 public void Execute(ExecutionToken token, CancellationToken cancel)
 {
     try
     {
         _requests.Add(token, cancel);
     }
     catch (OperationCanceledException)
     {
         token.SetCancelled();
     }
     catch (Exception ex)
     {
         token.SetFaulted(ex);
     }
 }
Exemplo n.º 3
0
        private void WriteToken(SocketWriter writer, ExecutionToken token)
        {
            try
            {
                _logger.Debug("{0} Received token {1}.", _code, token);

                var hasCommands = false;

                foreach (var command in ExecuteOperation(token))
                {
                    // some subscription commands are aggregated
                    // and produce no commands.
                    if (!hasCommands)
                    {
                        hasCommands = true;
                        _pending.Enqueue(token);
                    }
                    command.WriteTo(writer);
                }

                if (hasCommands)
                {
                    writer.Flush(); // using the async version kills performance, worth investigating why
                    _logger.Debug("{0} flushed buffer.", _code);
                }
            }
            catch (OperationCanceledException)
            {
                token.SetCancelled();
                throw;
            }
            catch (Exception ex)
            {
                token.SetFaulted(ex);
                throw;
            }
        }