syncx

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package syncx provides additional synchronization mechanisms and utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

type Lock chan struct{}

Lock is a mutually exclusive lock that supports cancelling acquire operation.

func NewLock

func NewLock() Lock

NewLock returns a new Lock that allows at most one goroutine to acquire it.

func (Lock) Acquire

func (c Lock) Acquire(ctx context.Context) error

Acquire locks c. If the lock is already in use, the calling goroutine blocks until either the lock is available or the context expires. It returns nil if the lock was acquired and a non-nil context error otherwise.

func (Lock) Release

func (c Lock) Release()

Release unlocks c. Unlike sync.Mutex, it is valid to release a Lock without a corresponding Acquire. In that case the next Acquire call will unlock the Release.

type Map

type Map[K any, V any] struct {
	// contains filtered or unexported fields
}

Map is a type-safe wrapper for sync.Map.

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

Delete is a type-safe wrapper for sync.Map’s Delete method.

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (value V, ok bool)

Load is a type-safe wrapper for sync.Map’s Load method.

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete is a type-safe wrapper for sync.Map’s LoadAndDelete method.

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore is a type-safe wrapper for sync.Map’s LoadOrStore method.

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(key K, value V) bool)

Range is a type-safe wrapper for sync.Map’s Range method.

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

Store is a type-safe wrapper for sync.Map’s Store method.

Jump to

Keyboard shortcuts

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