Files
Abstraction/vendor/github.com/enfipy/locker
2022-12-11 06:18:00 +00:00
..
2022-12-11 06:18:00 +00:00
2022-12-11 06:18:00 +00:00
2022-12-11 06:18:00 +00:00

Lightweight Golang Locker

Utility locker - simple and lightweight Golang locker based on sync.Map and sync.Pool

Installation:

To install via go get (needs golang version 1.11+ installed):

go get github.com/enfipy/locker

Usage:

To lock by key:

locker := locker.Initialize()
locker.Lock("key")
<code>
locker.Unlock("key")

To lock only read:

locker := locker.Initialize()
locker.RLock("key")
<code>
locker.RUnlock("key")

Test:

To run tests:

go test

Good explanation of sync package and why is RWMutex with RLock are useful

Reddit post where we discussed why removing the mutex after unlocking is worse than keeping