Categorygithub.com/DaanV2/go-locks
repositorypackage
1.1.0
Repository: https://github.com/daanv2/go-locks.git
Documentation: pkg.go.dev

# README

Go Locks

CI

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

go get github.com/DaanV2/go-locks

Usage

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()
}