protected override void OnDisconnection()
 {
     if (_current != null)
     {
         _current.SetCancelled();
         _current = null;
     }
 }
 private static void CancelToken(ExecutionToken token)
 {
     try
     {
         token.SetCancelled();
     }
     catch
     {
         // it does not matter
     }
 }
示例#3
0
 public void Execute(ExecutionToken token, CancellationToken cancel)
 {
     try
     {
         _requests.Add(token, cancel);
     }
     catch (OperationCanceledException)
     {
         token.SetCancelled();
     }
     catch (Exception ex)
     {
         token.SetFaulted(ex);
     }
 }
示例#4
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;
            }
        }