mapofmu

package
v0.0.0-...-63027bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package mapofmu provides locking per-key. For example, you can acquire a lock for a specific user ID and all other requests for that user ID will block until that entry is unlocked (effectively your work load will be run serially per-user ID), and yet have work for separate user IDs happen concurrently.

https://stackoverflow.com/questions/40931373/how-to-gc-a-map-of-mutexes-in-go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type M

type M[K comparable] struct {
	// contains filtered or unexported fields
}

M wraps a map of mutexes. Each key locks separately.

func New

func New[K comparable]() *M[K]

New returns an initalized M.

func (*M[K]) IsLocked

func (m *M[K]) IsLocked(key K) bool

IsLocked returns true if the key is locked.

func (*M[K]) Lock

func (m *M[K]) Lock(key K) Unlocker

Lock acquires a lock corresponding to this key. This method will never return nil and Unlock() must be called to release the lock when done.

type Unlocker

type Unlocker interface {
	Unlock()
}

Unlocker provides an Unlock method to release the lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL