protected virtual Task InitializePersistentState()
        {
            _requestLifeTime = new HttpRequestLifeTime(this, WriteQueue, Logger, ConnectionId);

            // Create the TCS that completes when the task returned by PersistentConnection.OnConnected does.
            _connectTcs = new TaskCompletionSource <object>();

            // Create a token that represents the end of this connection's life
            _connectionEndTokenSource = new SafeCancellationTokenSource();
            _connectionEndToken       = _connectionEndTokenSource.Token;

            // Handle the shutdown token's callback so we can end our token if it trips
            _hostRegistration = _hostShutdownToken.SafeRegister(state =>
            {
                ((SafeCancellationTokenSource)state).Cancel();
            },
                                                                _connectionEndTokenSource);

            // When the connection ends release the request
            _connectionEndRegistration = CancellationToken.SafeRegister(state =>
            {
                ((HttpRequestLifeTime)state).Complete();
            },
                                                                        _requestLifeTime);

            return(InitializeMessageId());
        }
 public RequestLifetime(ForeverTransport transport, HttpRequestLifeTime lifetime)
 {
     _lifetime  = lifetime;
     _transport = transport;
 }
        protected virtual Task InitializePersistentState()
        {
            _requestLifeTime = new HttpRequestLifeTime(this, WriteQueue, Logger, ConnectionId);

            // Create the TCS that completes when the task returned by PersistentConnection.OnConnected does.
            _connectTcs = new TaskCompletionSource<object>();

            // Create a token that represents the end of this connection's life
            _connectionEndTokenSource = new SafeCancellationTokenSource();
            _connectionEndToken = _connectionEndTokenSource.Token;

            // Handle the shutdown token's callback so we can end our token if it trips
            _hostRegistration = _hostShutdownToken.SafeRegister(state =>
            {
                ((SafeCancellationTokenSource)state).Cancel();
            },
            _connectionEndTokenSource);

            // When the connection ends release the request
            _connectionEndRegistration = CancellationToken.SafeRegister(state =>
            {
                ((HttpRequestLifeTime)state).Complete();
            },
            _requestLifeTime);

            return InitializeMessageId();
        }
 public RequestLifetime(ForeverTransport transport, HttpRequestLifeTime lifetime)
 {
     _lifetime = lifetime;
     _transport = transport;
 }