Documentation ¶
Overview ¶
Package mapmutex provides an extensible, type-safe mutex implementation TODO: use generics
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IntMapMutex ¶
IntMapMutex is a map mutex that allows locking on an int.
Example ¶
mapMutex := mapmutex.NewIntMapMutex() // second variable will be true lock0, _ := mapMutex.TryLock(0) lock1 := mapMutex.Lock(1) lock0.Unlock() lock1.Unlock()
Output:
func NewIntMapMutex ¶
func NewIntMapMutex() IntMapMutex
NewIntMapMutex creates a map mutex for locking on an integer.
type StringMapMutex ¶
StringMapMutex is an implementation of map mutex for string typed values.
Example ¶
ExampleMapMutex provides an example implementation of a map mutex.
mapMutex := mapmutex.NewStringMapMutex() lock1 := mapMutex.Lock("lock1") lock2 := mapMutex.Lock("lock2") lock1.Unlock() lock2.Unlock()
Output:
func NewStringMapMutex ¶
func NewStringMapMutex() StringMapMutex
NewStringMapMutex creates a map mutex for the string type.
type StringerMapMutex ¶
type StringerMapMutex interface { Lock(key fmt.Stringer) Unlocker TryLock(key fmt.Stringer) (Unlocker, bool) }
StringerMapMutex is an implementation of mapMutex for the fmt.Stringer conforming types.
Example ¶
vitalik := common.HexToAddress("0xab5801a7d398351b8be11c439e05c5b3259aec9b") tether := common.HexToAddress("0xdac17f958d2ee523a2206206994597c13d831ec7") mapMutex := mapmutex.NewStringerMapMutex() // second variable will be true vitalikLock, _ := mapMutex.TryLock(vitalik) tetherLock := mapMutex.Lock(tether) vitalikLock.Unlock() tetherLock.Unlock()
Output:
func NewStringerMapMutex ¶
func NewStringerMapMutex() StringerMapMutex
NewStringerMapMutex creates an initialized locker that locks on fmt.String.
Click to show internal directories.
Click to hide internal directories.