gmx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 1 Imported by: 1

README

gmx

Generic Mutex container types for Go, inspired by Rust's Mutex and RwLock.

It uses new language features introduced since go1.18:

Documentation

Overview

Generic Mutex container types for Go, inspired by Rust's Mutex and RwLock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutation added in v0.0.1

type Mutation[T any] func(*T)

Mutation represents mutable operation on a pointer

type Mutexer added in v0.0.1

type Mutexer[T any] interface {
	// Mutate inner value
	Do(Mutation[T])
	// Unwrap inner value
	Unwrap() T
}

Mutexer is implemented by Mx and RwMx

type Mx

type Mx[T any] struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

Generic Mutex container type

func Wrap

func Wrap[T any](x *T) *Mx[T]

Wrap a pointer into Mx

func (*Mx[T]) Do

func (m *Mx[T]) Do(op Mutation[T])

Do mutable operation on wrapped value guarded by sync.RWMutex

func (*Mx[T]) Unwrap

func (m *Mx[T]) Unwrap() T

Unwrap returns value references by the wrapped pointer

type RwMx

type RwMx[T any] struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

Generic Read-Write Mutex container type

func RwWrap

func RwWrap[T any](x *T) *RwMx[T]

Wrap a pointer into RwMx

func (*RwMx[T]) Do

func (m *RwMx[T]) Do(op Mutation[T])

Do mutable operation on wrapped value guarded by sync.RWMutex

func (*RwMx[T]) Unwrap

func (m *RwMx[T]) Unwrap() T

Unwrap returns value references by the wrapped pointer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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