util.Semaphore: initial commit

This commit is contained in:
Christian Schwarz
2018-02-27 00:20:32 +01:00
parent b34d0e1041
commit f76a0dec6d

17
util/semaphore.go Normal file
View File

@ -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
}