https://github.com/daanv2/go-locks
A simple library that provides pools of locks for Go. It is useful when you need to lock on a resource that cannot carry its lock. Such as files, network connections, etc.
https://github.com/daanv2/go-locks
go golang locks mutex pool
Last synced: 6 days ago
JSON representation
A simple library that provides pools of locks for Go. It is useful when you need to lock on a resource that cannot carry its lock. Such as files, network connections, etc.
- Host: GitHub
- URL: https://github.com/daanv2/go-locks
- Owner: DaanV2
- License: mit
- Created: 2024-03-03T10:03:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-02-14T00:04:05.000Z (4 months ago)
- Last Synced: 2026-02-14T06:28:59.365Z (4 months ago)
- Topics: go, golang, locks, mutex, pool
- Language: Go
- Homepage: https://pkg.go.dev/github.com/daanv2/go-locks
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Locks
[](https://github.com/DaanV2/go-locks/actions/workflows/pipeline.yaml)
A simple library that provides pools of locks for Go. It is useful when you need to lock on a resource that cannot carry its lock.
Such as files, network connections, etc.
## Install
```bash
go get github.com/daanv2/go-locks
```
## Usage
```go
package main
import (
"fmt"
"github.com/daanv2/go-locks"
)
func main() {
pool := locks.NewPool(100)
lock := pool.GetLock(uint64)
lock.Lock()
defer lock.Unlock()
// Do something with the resource
// For files:
key := locks.KeyForString("file.txt")
lock := pool.GetLock(key)
lock.Lock()
defer lock.Unlock()
}
```