keylock

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

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