Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 777 Bytes

README.md

File metadata and controls

38 lines (28 loc) · 777 Bytes

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