mapofmutex

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

https://stackoverflow.com/questions/40931373/how-to-gc-a-map-of-mutexes-in-go 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type M

type M struct {
	// contains filtered or unexported fields
}

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

func New

func New() *M

New returns an initalized M.

func (*M) Lock

func (m *M) Lock(key interface{}) 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 MapOfLimiter

type MapOfLimiter struct {
	M             *sync.Map
	CleanupThread *chan struct{}
}

func NewMapOfLimiter

func NewMapOfLimiter() *MapOfLimiter

func (*MapOfLimiter) Allow

func (m *MapOfLimiter) Allow(key interface{}) bool

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