sync

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package sync provides a locker implementation.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyLocked = errors.New("already locked")

ErrAlreadyLocked is returned when the lock is already locked.

Functions

This section is empty.

Types

type Key

type Key string

Key represents key of Locker.

func NewKey

func NewKey(key string) Key

NewKey creates a new instance of Key.

func (Key) String

func (k Key) String() string

String returns a string representation of this Key.

type Locker

type Locker interface {
	// Lock locks the mutex with a cancelable context
	Lock(ctx context.Context) error

	// TryLock locks the mutex if not already locked by another session.
	TryLock(ctx context.Context) error

	// Unlock unlocks the mutex.
	Unlock(ctx context.Context) error

	// RLock acquires a read lock with a cancelable context.
	RLock(ctx context.Context) error

	// RUnlock releases a read lock previously acquired by RLock.
	RUnlock(ctx context.Context) error
}

A Locker represents an object that can be locked and unlocked.

type LockerManager added in v0.6.0

type LockerManager struct {
	// contains filtered or unexported fields
}

LockerManager manages Lockers.

func New added in v0.6.0

func New() *LockerManager

New creates a new instance of LockerManager.

func (*LockerManager) NewLocker added in v0.6.0

func (c *LockerManager) NewLocker(
	_ context.Context,
	key Key,
) (Locker, error)

NewLocker creates locker of the given key.

Jump to

Keyboard shortcuts

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