18 lines
229 B
Go
18 lines
229 B
Go
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
|
|
}
|