diff --git a/control/semaphore.go b/control/semaphore.go new file mode 100644 index 0000000..4bba711 --- /dev/null +++ b/control/semaphore.go @@ -0,0 +1,25 @@ +package control + +type ( + Semaphore interface { + Acquire() + Release() + } + _semaphore struct { + c chan struct{} + } +) + +func NewSemaphore(count uint64) Semaphore { + return &_semaphore{ + c: make(chan struct{}, count), + } +} + +func (s *_semaphore) Acquire() { + s.c <- struct{}{} +} + +func (s *_semaphore) Release() { + <-s.c +}