syncext extends Go's standard sync package with practical concurrency primitives.
go get github.com/ofw/syncextRWMutex[T comparable] lets you lock per key without manually managing a sync.RWMutex per key.
package main
import (
"fmt"
"github.com/ofw/syncext"
)
func main() {
var m syncext.RWMutex[string]
unlock := m.Lock("user:42")
defer unlock()
fmt.Println("exclusive section for user:42")
}package main
import (
"fmt"
"github.com/ofw/syncext"
)
func main() {
var m syncext.RWMutex[string]
unlock := m.RLock("user:42")
defer unlock()
fmt.Println("shared read section for user:42")
}- The returned unlock function must be called exactly once.
- Locks are stored in an internal
map[T]*sync.RWMutexand are not evicted.
go test ./...
go test -bench=. ./...