keylock

package
v0.4.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package keylock provides per-key mutual-exclusion locks that honor context cancellation. A KeyMap[K] is a process-wide map of locks keyed by K; Acquire returns once the slot is free or ctx fires.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyMap

type KeyMap[K comparable] struct {
	// contains filtered or unexported fields
}

KeyMap holds one lock per key value, allocated on first use.

func New

func New[K comparable]() *KeyMap[K]

New constructs an empty KeyMap.

func (*KeyMap[K]) Acquire

func (m *KeyMap[K]) Acquire(ctx context.Context, key K) (release func(), err error)

Acquire blocks until the lock for key is held by the caller, or ctx is done. Returns ctx.Err on cancellation (lock not held). On success returns a release func — call it (typically deferred) to free the lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL