forked from External/ergo
simplify semaphore release code
This commit is contained in:
parent
2e9a0d4b2d
commit
549d06bc98
1 changed files with 2 additions and 12 deletions
|
|
@ -5,8 +5,6 @@ package utils
|
|||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -67,15 +65,7 @@ func (semaphore *Semaphore) AcquireWithContext(ctx context.Context) (acquired bo
|
|||
return
|
||||
}
|
||||
|
||||
// Release releases a semaphore. It never blocks. (This is not a license
|
||||
// to program spurious releases.)
|
||||
// Release releases a semaphore.
|
||||
func (semaphore *Semaphore) Release() {
|
||||
select {
|
||||
case <-(*semaphore):
|
||||
// good
|
||||
default:
|
||||
// spurious release
|
||||
log.Printf("spurious semaphore release (full to capacity %d)", cap(*semaphore))
|
||||
debug.PrintStack()
|
||||
}
|
||||
<-(*semaphore)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue