syncext

package
v5.30.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: Apache-2.0, MIT Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

type Mutex[T any] struct {
	// contains filtered or unexported fields
}

Mutex creates a type safe mutex wrapper ensuring one cannot access the values of a locked values without first gaining a lock.

func NewMutex deprecated

func NewMutex[T any](value T) *Mutex[T]

NewMutex creates a new Mutex for use.

Deprecated: use `syncext.NewMutex2(...)` instead which corrects design issues with the current implementation.

func (*Mutex[T]) Lock

func (m *Mutex[T]) Lock() T

Lock locks the Mutex and returns value for use, safe for mutation if

If the lock is already in use, the calling goroutine blocks until the mutex is available.

func (*Mutex[T]) PerformMut

func (m *Mutex[T]) PerformMut(f func(T) (T, error)) error

PerformMut safely locks and unlocks the Mutex values and performs the provided function returning its error if one otherwise setting the returned value as the new mutex value.

func (*Mutex[T]) TryLock

func (m *Mutex[T]) TryLock() resultext.Result[T, struct{}]

TryLock tries to lock Mutex and reports whether it succeeded. If it does the value is returned for use in the Ok result otherwise Err with empty value.

func (*Mutex[T]) Unlock

func (m *Mutex[T]) Unlock(value optionext.Option[T])

Unlock unlocks the Mutex accepting a value to set as the new or mutated value. It is optional to pass a new value to be set but NOT required for there reasons: 1. If the internal value is already mutable then no need to set as changes apply as they happen. 2. If there's a failure working with the locked value you may NOT want to set it, but still unlock. 3. Supports locked values that are not mutable.

It is a run-time error if the Mutex is not locked on entry to Unlock.

type Mutex2 added in v5.15.0

type Mutex2[T any] struct {
	// contains filtered or unexported fields
}

Mutex2 creates a type safe mutex wrapper ensuring one cannot access the values of a locked values without first gaining a lock.

func NewMutex2 added in v5.15.0

func NewMutex2[T any](value T) Mutex2[T]

NewMutex2 creates a new Mutex for use.

func (Mutex2[T]) Lock added in v5.15.0

func (m Mutex2[T]) Lock() MutexGuard[T, *sync.Mutex]

Lock locks the Mutex and returns value for use, safe for mutation if

If the lock is already in use, the calling goroutine blocks until the mutex is available.

func (Mutex2[T]) PerformMut added in v5.15.0

func (m Mutex2[T]) PerformMut(f func(T))

PerformMut safely locks and unlocks the Mutex values and performs the provided function returning its error if one otherwise setting the returned value as the new mutex value.

func (Mutex2[T]) TryLock added in v5.15.0

func (m Mutex2[T]) TryLock() resultext.Result[MutexGuard[T, *sync.Mutex], struct{}]

TryLock tries to lock Mutex and reports whether it succeeded. If it does the value is returned for use in the Ok result otherwise Err with empty value.

type MutexGuard added in v5.15.1

type MutexGuard[T any, M interface{ Unlock() }] struct {

	// T is the inner generic type of the Mutex
	T T
	// contains filtered or unexported fields
}

MutexGuard protects the inner contents of a Mutex2 for safety and unlocking.

func (MutexGuard[T, M]) Unlock added in v5.15.1

func (g MutexGuard[T, M]) Unlock()

Unlock unlocks the Mutex2 value.

type RMutexGuard added in v5.15.1

type RMutexGuard[T any] struct {

	// T is the inner generic type of the Mutex
	T T
	// contains filtered or unexported fields
}

RMutexGuard protects the inner contents of a RWMutex2 for safety and unlocking.

func (RMutexGuard[T]) RUnlock added in v5.15.1

func (g RMutexGuard[T]) RUnlock()

RUnlock unlocks the RWMutex2 value.

type RWMutex

type RWMutex[T any] struct {
	// contains filtered or unexported fields
}

RWMutex creates a type safe RWMutex wrapper ensuring one cannot access the values of a locked values without first gaining a lock.

func NewRWMutex deprecated

func NewRWMutex[T any](value T) *RWMutex[T]

NewRWMutex creates a new RWMutex for use.

Deprecated: use `syncext.NewRWMutex2(...)` instead which corrects design issues with the current implementation.

func (*RWMutex[T]) Lock

func (m *RWMutex[T]) Lock() T

Lock locks the Mutex and returns value for use, safe for mutation if

If the lock is already in use, the calling goroutine blocks until the mutex is available.

func (*RWMutex[T]) Perform

func (m *RWMutex[T]) Perform(f func(T) error) error

Perform safely locks and unlocks the RWMutex read-only values and performs the provided function.

func (*RWMutex[T]) PerformMut

func (m *RWMutex[T]) PerformMut(f func(T) (T, error)) error

PerformMut safely locks and unlocks the RWMutex mutable values and performs the provided function.

func (*RWMutex[T]) RLock

func (m *RWMutex[T]) RLock() T

RLock locks the RWMutex for reading and returns the value for read-only use. It should not be used for recursive read locking; a blocked Lock call excludes new readers from acquiring the lock

func (*RWMutex[T]) RUnlock

func (m *RWMutex[T]) RUnlock()

RUnlock undoes a single RLock call; it does not affect other simultaneous readers. It is a run-time error if rw is not locked for reading on entry to RUnlock.

func (*RWMutex[T]) TryLock

func (m *RWMutex[T]) TryLock() resultext.Result[T, struct{}]

TryLock tries to lock RWMutex and returns the value in the Ok result if successful. If it does the value is returned for use in the Ok result otherwise Err with empty value.

func (*RWMutex[T]) TryRLock

func (m *RWMutex[T]) TryRLock() resultext.Result[T, struct{}]

TryRLock tries to lock RWMutex for reading and returns the value in the Ok result if successful. If it does the value is returned for use in the Ok result otherwise Err with empty value.

func (*RWMutex[T]) Unlock

func (m *RWMutex[T]) Unlock(value optionext.Option[T])

Unlock unlocks the Mutex accepting a value to set as the new or mutated value. It is optional to pass a new value to be set but NOT required for there reasons: 1. If the internal value is already mutable then no need to set as changes apply as they happen. 2. If there's a failure working with the locked value you may NOT want to set it, but still unlock. 3. Supports locked values that are not mutable.

It is a run-time error if the Mutex is not locked on entry to Unlock.

type RWMutex2 added in v5.15.0

type RWMutex2[T any] struct {
	// contains filtered or unexported fields
}

RWMutex2 creates a type safe RWMutex wrapper ensuring one cannot access the values of a locked values without first gaining a lock.

func NewRWMutex2 added in v5.15.0

func NewRWMutex2[T any](value T) RWMutex2[T]

NewRWMutex2 creates a new RWMutex for use.

func (RWMutex2[T]) Lock added in v5.15.0

func (m RWMutex2[T]) Lock() MutexGuard[T, *sync.RWMutex]

Lock locks the Mutex and returns value for use, safe for mutation if

If the lock is already in use, the calling goroutine blocks until the mutex is available.

func (RWMutex2[T]) Perform added in v5.15.0

func (m RWMutex2[T]) Perform(f func(T))

Perform safely locks and unlocks the RWMutex read-only values and performs the provided function.

func (RWMutex2[T]) PerformMut added in v5.15.0

func (m RWMutex2[T]) PerformMut(f func(T))

PerformMut safely locks and unlocks the RWMutex mutable values and performs the provided function.

func (RWMutex2[T]) RLock added in v5.15.0

func (m RWMutex2[T]) RLock() RMutexGuard[T]

RLock locks the RWMutex for reading and returns the value for read-only use. It should not be used for recursive read locking; a blocked Lock call excludes new readers from acquiring the lock

func (RWMutex2[T]) TryLock added in v5.15.0

func (m RWMutex2[T]) TryLock() resultext.Result[MutexGuard[T, *sync.RWMutex], struct{}]

TryLock tries to lock RWMutex and returns the value in the Ok result if successful. If it does the value is returned for use in the Ok result otherwise Err with empty value.

func (RWMutex2[T]) TryRLock added in v5.15.0

func (m RWMutex2[T]) TryRLock() resultext.Result[RMutexGuard[T], struct{}]

TryRLock tries to lock RWMutex for reading and returns the value in the Ok result if successful. If it does the value is returned for use in the Ok result otherwise Err with empty value.

Jump to

Keyboard shortcuts

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