go-lockable provides a simple implementation for acquiring locks by key.
This can be useful when multiple goroutines need to manipulate a map atomically using async calls without blocking access to all keys or when access to certain ressource needs to be partially locked.
This pkg does not use any 3rd party dependencies, only std packages.
go get github.com/MysteriousPotato/go-lockable
package main
import (
"github.com/MysteriousPotato/go-lockable"
)
func main() {
// Using lockable like a mutex:
lock := lockable.New[string]()
lock.LockKey("potato")
defer lock.UnlockKey("potato")
// Using go-lockable built-in Map type:
lockableMap := lockable.NewMap[string, int]()
lockableMap.LockKey("potato")
defer lockableMap.UnlockKey("potato")
// Do async stuff....
lockableMap.Store("potato", 10)
}
For more detailed examples, please refer to the Documentation_
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Distributed under the MIT License. See LICENSE for more information.