Skip to content

Repository files navigation

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

About

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.

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages