Skip to content

MysteriousPotato/go-lockable

Repository files navigation


go-lockable

key based lock


About The Project

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.

Getting Started

Installation

go get github.com/MysteriousPotato/go-lockable

Usage

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_

Roadmap

See the open issues for a full list of proposed features (and known issues).

Contributing

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".

License

Distributed under the MIT License. See LICENSE for more information.