public HttpRequestLifeTime(TransportDisconnectBase transport, TaskQueue writeQueue, ILogger logger, string connectionId)
 {
     _transport = transport;
     _logger = logger;
     _connectionId = connectionId;
     _writeQueue = writeQueue;
 }
        protected TransportDisconnectBase(HttpContext context, ITransportHeartbeat heartbeat, IPerformanceCounterManager performanceCounterManager, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory, IMemoryPool pool)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (heartbeat == null)
            {
                throw new ArgumentNullException("heartbeat");
            }

            if (performanceCounterManager == null)
            {
                throw new ArgumentNullException("performanceCounterManager");
            }

            if (applicationLifetime == null)
            {
                throw new ArgumentNullException("applicationLifetime");
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException("loggerFactory");
            }

            Pool = pool;

            _context = context;
            _heartbeat = heartbeat;
            _counters = performanceCounterManager;
            _hostShutdownToken = applicationLifetime.ApplicationStopping;
            _requestAborted = context.RequestAborted;

            // Queue to protect against overlapping writes to the underlying response stream
            WriteQueue = new TaskQueue();
            _logger = loggerFactory.CreateLogger(GetType().FullName);
        }
        private static Task Drain(TaskQueue queue, ILogger logger)
        {
            if (queue == null)
            {
                return TaskAsyncHelper.Empty;
            }

            var tcs = new TaskCompletionSource<object>();
            
            queue.Drain().Catch(logger).ContinueWith(task =>
            {
                tcs.SetResult(null);
            });

            return tcs.Task;
        }
 private void InitializeCore()
 {
     if (UsingTaskQueue)
     {
         Task task = DrainPreviousQueue();
         _queue = new TaskQueue(task, _size);
         _queue.QueueSizeCounter = _perfCounters.ScaleoutSendQueueLength;
     }
 }