Codebase list golang-gopkg-eapache-go-resiliency.v1 / ad13f17
Semaphore empty check added Sudersen Archakam 6 years ago
2 changed file(s) with 25 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
4242 func (s *Semaphore) Release() {
4343 <-s.sem
4444 }
45
46 // IsEmpty would return true if none acquired ar that moment of time, otherwise false.
47 func (s *Semaphore) IsEmpty() bool {
48 return len(s.sem) == 0
49 }
4444 }
4545 }
4646
47 func TestSemaphoreEmpty(t *testing.T) {
48 sem := New(2, 200*time.Millisecond)
49
50 if !sem.IsEmpty() {
51 t.Error("semaphore should be empty")
52 }
53
54 sem.Acquire()
55
56 if sem.IsEmpty() {
57 t.Error("semaphore should not be empty")
58 }
59
60 sem.Release()
61
62 if !sem.IsEmpty() {
63 t.Error("semaphore should be empty")
64 }
65 }
66
4767 func ExampleSemaphore() {
4868 sem := New(3, 1*time.Second)
4969