Documentation
¶
Overview ¶
Package singleflight 提供重复函数调用抑制机制
Index ¶
- Variables
- type GenericGroup
- type GenericResult
- type Group
- func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool)
- func (g *Group) DoChan(key string, fn func() (interface{}, error)) <-chan Result
- func (g *Group) DoContext(ctx context.Context, key string, ...) (v interface{}, err error, shared bool)
- func (g *Group) Forget(key string)
- type Result
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrForgotten = errors.New("call was forgotten")
ErrForgotten 表示调用被忘记
Functions ¶
This section is empty.
Types ¶
type GenericGroup ¶
type GenericGroup[T any] struct { // contains filtered or unexported fields }
GenericGroup 泛型版本的 singleflight
func NewGenericGroup ¶
func NewGenericGroup[T any]() *GenericGroup[T]
NewGenericGroup 创建泛型 singleflight
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group 表示一类工作的 singleflight 组
func (*Group) Do ¶
func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool)
Do 执行给定函数并返回结果,确保同一时间 对于同一个 key 只有一个执行在进行中。 如果有重复调用,调用者会等待原始调用完成并收到相同的结果。
Click to show internal directories.
Click to hide internal directories.