Skip to content

ofw/syncext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

syncext

syncext extends Go's standard sync package with practical concurrency primitives.

Install

go get github.com/ofw/syncext

Keyed RWMutex[T]

RWMutex[T comparable] lets you lock per key without manually managing a sync.RWMutex per key.

Write lock

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

Read lock

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

Notes

  • The returned unlock function must be called exactly once.
  • Locks are stored in an internal map[T]*sync.RWMutex and are not evicted.

Development

go test ./...
go test -bench=. ./...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages