Files
commander/semaphore.go
2024-08-01 23:42:30 +03:00

32 lines
339 B
Go

package commander
func NewSemaphore(len int) Semaphore {
if len == 0 {
return nil
}
return make(Semaphore, len)
}
type Semaphore chan struct{}
func (s Semaphore) Acquire() {
if s == nil {
return
}
s <- struct{}{}
}
func (s Semaphore) Release() {
if s == nil {
return
}
<-s
}
func (s Semaphore) Close() {
close(s)
}