public void IncrementDisposeTryDecrement()
        {         //****************************************
            var MyLock = new AsyncCounter();

            //****************************************

            MyLock.Increment();

            _ = MyLock.DisposeAsync();

            Assert.IsTrue(MyLock.TryDecrement());

            Assert.IsFalse(MyLock.TryDecrement());

            //****************************************

            Assert.AreEqual(0, MyLock.WaitingCount, "Waiter still registered");
            Assert.AreEqual(0, MyLock.CurrentCount, "Count not zero");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to take an item from the collection without waiting
        /// </summary>
        /// <param name="item">The item that was removed from the collection</param>
        /// <returns>True if an item was removed without waiting, False if we would have to wait, or if the collection is completed and empty</returns>
        public bool TryTake(
#if !NETSTANDARD2_0
            [MaybeNullWhen(false)]
#endif
            out T item
            )
        {
            // Is there an item to take?
            if (!_UsedSlots.TryDecrement())
            {
                item = default !;