Exemplo n.º 1
0
        /// <summary>
        /// Wait for an instance to become available and then get it.
        /// </summary>
        public async Task <IPoolToken> GetAsync()
        {
            await _objectsAvailable.WaitAsync();

            SemaphoreSlim semaphoreToBeReleased = _objectsAvailable;

            try
            {
                T obj;
                if (!_objects.TryTake(out obj))
                {
                    throw ContractUtilities.AssertFailure("Semaphore was available, but pool is empty.");
                }

                var token = new BoundedPoolToken(obj, this);
                semaphoreToBeReleased = null;
                return(token);
            }
            finally
            {
                if (semaphoreToBeReleased != null)
                {
                    _objectsAvailable.Release();
                }
            }
        }
Exemplo n.º 2
0
        private async Task<bool> ExecuteReaderImplAsync(string command, Func<SQLiteDataReader, ReadResponse> readFunc, params SQLiteParameter[] parameters)
        {
            using (var cmd = new SQLiteCommand(command, Connection))
            {
                cmd.Parameters.AddRange(parameters);
#pragma warning disable AsyncFixer02 // Long running or blocking operations under an async method
                using (SQLiteDataReader reader = cmd.ExecuteReader())
                {
                    var done = false;

                    while (!done && await reader.ReadAsync())
                    {
                        var response = readFunc(reader);
                        switch (response)
                        {
                            case ReadResponse.ContinueReading:
                                continue;
                            case ReadResponse.StopReadingIgnoreFurther:
                                done = true;
                                break;
                            case ReadResponse.StopReadingAssertEnd:
                                Contract.Assert(!reader.Read());
#pragma warning restore AsyncFixer02 // Long running or blocking operations under an async method
                                break;
                            default:
                                throw ContractUtilities.AssertFailure("unexpected ReadResponse");
                        }
                    }
                }
            }

            return true;
        }
Exemplo n.º 3
0
        public static bool IndicatesFailure(this PipState current)
        {
            Contract.Ensures(ContractUtilities.Static(IsTerminal(current)));

            switch (current)
            {
            case PipState.Ignored:
            case PipState.Waiting:
            case PipState.Ready:
            case PipState.Running:
                return(false);    // Non-terminal

            case PipState.Done:
                return(false);    // Terminal but successful

            case PipState.Skipped:
                return(false);    // Terminal but not considered a failure

            case PipState.Failed:
            case PipState.Canceled:
                return(true);    // Oh no!

            default:
                throw Contract.AssertFailure("Unhandled Pip State");
            }
        }
Exemplo n.º 4
0
        public static bool IndicatesExecution(this PipResultStatus result)
        {
            Contract.Ensures(ContractUtilities.Static(
                                 !Contract.Result <bool>() ||
                                 result == PipResultStatus.UpToDate || result == PipResultStatus.NotMaterialized || result == PipResultStatus.DeployedFromCache ||
                                 result == PipResultStatus.Succeeded || result == PipResultStatus.Failed || result == PipResultStatus.Canceled));

            return(result == PipResultStatus.UpToDate || result == PipResultStatus.NotMaterialized || result == PipResultStatus.DeployedFromCache ||
                   result == PipResultStatus.Succeeded || result == PipResultStatus.Failed || result == PipResultStatus.Canceled);
        }