lock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 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 Locker

type Locker interface {
	// Acquire blocks until the lock for key is obtained or the context is cancelled.
	// If ttl is greater than zero, the lock is automatically released after the duration.
	Acquire(ctx context.Context, key string, ttl time.Duration) error

	// TryLock attempts to obtain the lock without waiting. It returns true on success.
	TryLock(ctx context.Context, key string, ttl time.Duration) (bool, error)

	// Release frees the lock for the given key.
	Release(ctx context.Context, key string) error
}

Locker defines the interface for distributed or local locks.

Example:

// Assuming a RedisLocker implementation
locker := NewRedisLocker(redisClient)
locker.Acquire(ctx, "my-resource", 5*time.Second)

Jump to

Keyboard shortcuts

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