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