Skip to content
Berkay Akyazı edited this page Mar 18, 2022 · 1 revision

mtxmap

import "github.com/bakyazi/mtxmap"

Index

type MutexMap

MutexMap is a map containing sync.Map whose value is mutexEntity it use as key based mutex map. Check if mutexEntities is expired every second if it is expired then deletes it from map

type MutexMap struct {
    // contains filtered or unexported fields
}
func NewMutexMap(ttl time.Duration, cleanInterval time.Duration) *MutexMap

NewMutexMap creates and return new MutexMap object

func (*MutexMap) Len

func (m *MutexMap) Len() int

Len returns length of key set of MutexMap

func (*MutexMap) Lock

func (m *MutexMap) Lock(key interface{}) func()

Lock firstly creates a mutex if there is no mutex with given key

if mutex with given key is already stored in map then retrieves it and tries to lock that mutex

if a mutex is newly created then increments size

return unlock function of the mutex of that key

func (*MutexMap) SetTTL

func (m *MutexMap) SetTTL(t time.Duration)

SetTTL sets TTL parameter of MutexMap

func (*MutexMap) Start

func (m *MutexMap) Start()

Start starts cleaner goroutine of MutexMap

func (*MutexMap) Stop

func (m *MutexMap) Stop()

Stop stops the cleaner goroutine of MutexMap

func (*MutexMap) Unlock

func (m *MutexMap) Unlock(key interface{})

Unlock if there is a mutex with given key, unlocks it

Generated by gomarkdoc