示例#1
0
 private async Task DisposeStatementAsync(ReservedForStatement reservationObject)
 {
     try
     {
         await this.UseStreamWithinStatementAsync(reservationObject, async() => await this.PerformDisposeStatementAsync(reservationObject));
     }
     finally
     {
         Interlocked.Exchange(ref this._currentlyExecutingStatement, NotInUse.Instance);
     }
 }
示例#2
0
 private async Task UseStreamOutsideStatementAsync(Func <Task> action, ReservedForStatement reservedState, Boolean oneTimeOnly)
 {
     if (ReferenceEquals(Interlocked.CompareExchange(ref this._currentlyExecutingStatement, reservedState, NotInUse.Instance), NotInUse.Instance))
     {
         try
         {
             await this.UseStreamWithinStatementAsync(reservedState, action);
         }
         finally
         {
             if (oneTimeOnly)
             {
                 Interlocked.Exchange(ref this._currentlyExecutingStatement, NotInUse.Instance);
             }
         }
     }
     else
     {
         throw new InvalidOperationException("The connection is currently being used by another statement.");
     }
 }
示例#3
0
        public async Task <T> UseStreamWithinStatementAsync <T>(ReservedForStatement reservedState, Func <Task <T> > action)
        {
            ArgumentValidator.ValidateNotNull(nameof(reservedState), reservedState);
            ConnectionStreamUsageState prevState;

            if (ReferenceEquals((prevState = Interlocked.CompareExchange(ref this._currentlyExecutingStatement, reservedState.UsageState, reservedState)), reservedState) ||  // Transition
                ReferenceEquals(prevState, reservedState.UsageState)  // Re-entrance
                )
            {
                try
                {
                    return(await action());
                }
                finally
                {
                    Interlocked.Exchange(ref this._currentlyExecutingStatement, prevState);
                }
            }
            else
            {
                throw new InvalidOperationException("The stream is not reserved for this statement.");
            }
        }
示例#4
0
 protected abstract Task <(TEnumerableItem, MoveNextAsyncDelegate <TEnumerableItem>)> ExecuteStatement(TStatement stmt, ReservedForStatement reservationObject);
示例#5
0
 protected abstract Task PerformDisposeStatementAsync(ReservedForStatement reservationObject);