keylock

package
v2.47.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyLock

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

KeyLock is a simple implementation of key based locks with ttl's on them

func NewKeyLock

func NewKeyLock[K comparable]() *KeyLock[K]

func (*KeyLock[K]) Lock

func (kl *KeyLock[K]) Lock(key K, timeout time.Duration, ttl time.Duration) (handle int64)

Lock attempts to lock the key for the given duration ttl, blocking until it succeeds or the timeout passes.

Specifically, if the key is currently locked by another caller and cannot be obtained within timeout, Lock returns -1. Otherwise, Lock returns a non-negative handle that can be passed to KeyLock.Lock to unlock the key before the ttl expires. (The lock handle guards against the case where callers attempt to unlock keys that have already expired and have since been re-locked by a different caller.)

func (*KeyLock[K]) Unlock

func (kl *KeyLock[K]) Unlock(key K, handle int64)

Jump to

Keyboard shortcuts

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