github.com/altipla-consulting/ravendb-go-client@v0.1.3/semaphore.go (about)

     1  package ravendb
     2  
     3  // Semaphore is a Go implementation of Java's Semaphore
     4  type Semaphore struct {
     5  	c chan struct{}
     6  }
     7  
     8  func NewSemaphore(cap int) *Semaphore {
     9  	return &Semaphore{
    10  		c: make(chan struct{}, cap),
    11  	}
    12  }
    13  
    14  func (s *Semaphore) acquire() {
    15  	s.c <- struct{}{}
    16  }
    17  
    18  func (s *Semaphore) release() {
    19  	<-s.c
    20  }