xtypact

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package xtypact is the EXPERIMENTAL package of typact.

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 is a value holding mutex using sync.Mutex.

func NewMutex

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

NewMutex returns Mutex with the given value.

func (*Mutex[T]) Lock

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

Lock acquires a lock on the mutex and returns the value.

See sync.Mutex for more details.

func (*Mutex[T]) Set

func (m *Mutex[T]) Set(val T)

Set acquires a lock and updates the internal value to val.

func (*Mutex[T]) TryLock

func (m *Mutex[T]) TryLock() (T, bool)

TryLock tries to lock the mutex and reports the whether it succeeded.

See sync.Mutex for more details.

func (*Mutex[T]) Unlock

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

Unlock releases the lock on the mutex.

See sync.Mutex for more details.

func (*Mutex[T]) UnsafeSet

func (m *Mutex[T]) UnsafeSet(val T)

UnsafeSet updates the internal value to val.

WARN: It is the responsibility of the caller to acquire a lock first!

func (*Mutex[T]) WithLock

func (m *Mutex[T]) WithLock(fn func(T) T) T

WithLock acquires a lock, calls fn with the value and updates the internal value with the one returned by fn. The lock is released once this method returns.

The method returns the value returned by fn, i.e., the change value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳