mirror of
https://github.com/PeernetOfficial/Abstraction.git
synced 2026-07-19 11:57:50 +01: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
Links:
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