diff --git a/util/semaphore.go b/util/semaphore.go new file mode 100644 index 0000000..2a0d509 --- /dev/null +++ b/util/semaphore.go @@ -0,0 +1,17 @@ +package util + +type Semaphore struct { + c chan struct{} +} + +func NewSemaphore(cap int) Semaphore { + return Semaphore{make(chan struct{}, cap)} +} + +func (s Semaphore) Down() { + s.c <- struct{}{} +} + +func (s Semaphore) Up() { + <-s.c +}