public void WaitAndRelease() { var semaphore = new AsyncSemaphore(5, 10); var acquire = semaphore.WaitAndRelease(); Assert.Equal(4, semaphore.CurrentCount); acquire.Dispose(); Assert.Equal(5, semaphore.CurrentCount); acquire = semaphore.WaitAndRelease(5); Assert.Equal(0, semaphore.CurrentCount); acquire.Dispose(); Assert.Equal(5, semaphore.CurrentCount); }
public void WaitAndRelease_Dispose() { var semaphore = new AsyncSemaphore(1, 1); Assert.Equal(1, semaphore.CurrentCount); using (semaphore.WaitAndRelease()) { Assert.Equal(0, semaphore.CurrentCount); } Assert.Equal(1, semaphore.CurrentCount); }