3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 20:09:41 +01:00

simplify semaphore release code

This commit is contained in:
Shivaram Lingamneni 2021-04-07 08:33:19 -04:00
parent 2e9a0d4b2d
commit 549d06bc98

View File

@ -5,8 +5,6 @@ package utils
import ( import (
"context" "context"
"log"
"runtime/debug"
"time" "time"
) )
@ -67,15 +65,7 @@ func (semaphore *Semaphore) AcquireWithContext(ctx context.Context) (acquired bo
return return
} }
// Release releases a semaphore. It never blocks. (This is not a license // Release releases a semaphore.
// to program spurious releases.)
func (semaphore *Semaphore) Release() { func (semaphore *Semaphore) Release() {
select { <-(*semaphore)
case <-(*semaphore):
// good
default:
// spurious release
log.Printf("spurious semaphore release (full to capacity %d)", cap(*semaphore))
debug.PrintStack()
}
} }