sync

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

This package provides an interface to functions and structs in the standard sync package to facilitate mocking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSync

func NewSync() syncFacade

Types

type Cond

type Cond interface {
	Broadcast()
	Signal()
	Wait()
}

type Locker

type Locker = sync.Locker

type Map

type Map interface {
	Clear()
	CompareAndDelete(any, any) bool
	CompareAndSwap(any, any, any) bool
	Delete(any)
	Load(any) (any, bool)
	LoadAndDelete(any) (any, bool)
	LoadOrStore(any, any) (any, bool)
	Range(func(any, any) bool)
	Store(any, any)
	Swap(any, any) (any, bool)
}

type Mutex

type Mutex interface {
	Lock()
	TryLock() bool
	Unlock()
}

type MutexOption added in v0.0.11

type MutexOption func(mut *sync.Mutex)

MutexOption allows you to set options on a mutex in the NewMutex constructor

func WithLocked added in v0.0.11

func WithLocked() MutexOption

Create a locked Mutex

type Once

type Once interface {
	Do(func())
}

type Pool

type Pool interface {
	Get() any
	Put(any)
}

type PoolOption added in v0.0.11

type PoolOption func(pool *sync.Pool)

PoolOption allows you to set options on a pool in the NewPool constructor

func WithNew added in v0.0.11

func WithNew(f func() any) PoolOption

Create a pool with a given New function

type RWMutex

type RWMutex interface {
	Lock()
	RLock()
	RLocker() Locker
	RUnlock()
	TryLock() bool
	TryRLock() bool
	Unlock()
}

type RWMutexOption added in v0.0.11

type RWMutexOption func(mut *sync.RWMutex)

RWMutexOption allows you to set options on a rw mutex in the NewRWMutex constructor

func WithRLocked added in v0.0.11

func WithRLocked() RWMutexOption

Create a read locked RWMutex

func WithWLocked added in v0.0.11

func WithWLocked() RWMutexOption

Create a write locked RWMutex

type Sync

type Sync interface {
	// Functions:
	OnceFunc(func()) func()

	// Constructors:
	NewCond(Locker) Cond
	NewMap() Map
	NewMutex(...MutexOption) Mutex
	NewOnce() Once
	NewPool(...PoolOption) Pool
	NewRWMutex(...RWMutexOption) RWMutex
	NewWaitGroup(...WaitGroupOption) WaitGroup
}

type WaitGroup

type WaitGroup interface {
	Add(int)
	Done()
	Wait()
}

type WaitGroupOption added in v0.0.11

type WaitGroupOption func(wg *sync.WaitGroup)

waitGroupOption allows you to set options on a wait group in the NewWaitGroup constructor

func WithCount added in v0.0.11

func WithCount(nbr uint8) WaitGroupOption

Create a wait group with the given initial count

Jump to

Keyboard shortcuts

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