sync

package
v1.7.8 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package singleflight provides a duplicate function call suppression mechanism.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFloat32

func AddFloat32(addr *float32, delta float32) (new float32)

func AddFloat64

func AddFloat64(addr *float64, delta float64) (new float64)

AddFloat64 add delta to given address atomically

func CasItem

func CasItem(p *unsafe.Pointer, old, new *DirectItem) bool

func CasNode

func CasNode[T any](p *unsafe.Pointer, old, new *Node[T]) bool

func SubUint32

func SubUint32(addr *uint32, delta uint32) (new uint32)

func SubUint64

func SubUint64(addr *uint64, delta uint64) (new uint64)

func WaitGroupState

func WaitGroupState(wg *sync.WaitGroup) (counter int32, wcounter uint32)

WaitGroupState返回 sync.WaitGroup 的状态,

func WaitGroupStopWait

func WaitGroupStopWait(wg *sync.WaitGroup)

Types

type DirectItem

type DirectItem struct {
	Next  unsafe.Pointer
	Value any
}

func LoadItem

func LoadItem(p *unsafe.Pointer) *DirectItem

type Group added in v1.7.8

type Group struct {
	// contains filtered or unexported fields
}

Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.

func (*Group) Do added in v1.7.8

func (g *Group) Do(key any, fn func() (any, error)) (v any, err error, shared bool)

Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. The return value shared indicates whether v was given to multiple callers.

func (*Group) DoChan added in v1.7.8

func (g *Group) DoChan(key any, fn func() (any, error)) <-chan Result

DoChan is like Do but returns a channel that will receive the results when they are ready.

The returned channel will not be closed.

func (*Group) Forget added in v1.7.8

func (g *Group) Forget(key string)

Forget tells the singleflight to forget about a key. Future calls to Do for this key will call the function rather than waiting for an earlier call to complete.

type Node

type Node[T any] struct {
	Next  atomic.Pointer[Node[T]]
	Value T
}

性能比用DirectItem差

func LoadNode

func LoadNode[T any](p *unsafe.Pointer) *Node[T]

type Pool added in v1.6.8

type Pool[T any] struct {
	// contains filtered or unexported fields
}

func NewPool added in v1.7.2

func NewPool[T any](fn func() T) *Pool[T]

func (*Pool[T]) Get added in v1.6.8

func (p *Pool[T]) Get() T

Get gets a T from the pool, or creates a new one if the pool is empty.

func (*Pool[T]) Put added in v1.6.8

func (p *Pool[T]) Put(x T)

Put returns x into the pool.

type Result added in v1.7.8

type Result struct {
	Val    any
	Err    error
	Shared bool
}

Result holds the results of Do, so they can be passed on a channel.

type WaitGroup

type WaitGroup struct {
	// contains filtered or unexported fields
}

运行计数,等待计数,信号计数

func (*WaitGroup) State

func (wg *WaitGroup) State() (counter int32, wcounter uint32)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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