package sync
import "github.com/go-playground/pkg/v5/sync"
Index ¶
- type Mutex
- func NewMutex[T any](value T) *Mutex[T]
- func (m *Mutex[T]) Lock() T
- func (m *Mutex[T]) PerformMut(f func(T))
- func (m *Mutex[T]) TryLock() result.Result[T, struct{}]
- func (m *Mutex[T]) Unlock()
- type RWMutex
- func NewRWMutex[T any](value T) *RWMutex[T]
- func (m *RWMutex[T]) Lock() T
- func (m *RWMutex[T]) Perform(f func(T))
- func (m *RWMutex[T]) PerformMut(f func(T))
- func (m *RWMutex[T]) RLock() T
- func (m *RWMutex[T]) RUnlock()
- func (m *RWMutex[T]) TryLock() result.Result[T, struct{}]
- func (m *RWMutex[T]) TryRLock() result.Result[T, struct{}]
- func (m *RWMutex[T]) Unlock()
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 ¶
NewMutex creates a new Mutex for use.
func (*Mutex[T]) Lock ¶
func (m *Mutex[T]) Lock() T
Lock locks the Mutex and returns value for mutable use. 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))
PerformMut safely locks and unlocks the Mutex values and performs the provided function.
Too bad Go doesn't support PerformMut[R any](func(T) R) R syntax :(
func (*Mutex[T]) TryLock ¶
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()
Unlock unlocks the Mutex. It is a run-time error if the Mutex is not locked on entry to Unlock.
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 ¶
NewRWMutex creates a new RWMutex for use.
func (*RWMutex[T]) Lock ¶
func (m *RWMutex[T]) Lock() T
Lock locks mutex and returns values for mutable use.
func (*RWMutex[T]) Perform ¶
func (m *RWMutex[T]) Perform(f func(T))
Perform safely locks and unlocks the RWMutex read-only values and performs the provided function.
Too bad Go doesn't support Perform[R any](func(T) R) R syntax :(
func (*RWMutex[T]) PerformMut ¶
func (m *RWMutex[T]) PerformMut(f func(T))
PerformMut safely locks and unlocks the RWMutex mutable values and performs the provided function.
Too bad Go doesn't support PerformMut[R any](func(T) R) R syntax :(
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 ¶
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 ¶
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()
Unlock unlocks mutable lock for values.
Source Files ¶
- Version
- v5.6.0
- Published
- Apr 28, 2022
- Platform
- darwin/amd64
- Imports
- 2 packages
- Last checked
- 1 minute ago –
Tools for package owners.