singleflight

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

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

singleflight Call, only call fn once it's a wrapper of sync.Once to store return values

func NewCall

func NewCall(fn func() (interface{}, error)) *Call

func (*Call) Do

func (c *Call) Do() (interface{}, error)

func (*Call) DoChan added in v0.1.7

func (c *Call) DoChan() <-chan Result

type Group

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

a group of Call, use key to identify

func (*Group) Do

func (g *Group) Do(key string, fn func() (interface{}, error), forgetAfter time.Duration) (interface{}, error)

about forgetAfter: - timer start before fn be called - only make sense if this call not hit cache, so you can't reset forget time - non-positive value means never forget

func (*Group) DoChan added in v0.1.7

func (g *Group) DoChan(key string, fn func() (interface{}, error), forgetAfter time.Duration) <-chan Result

unblock Do, return a result channel

func (*Group) Forget

func (g *Group) Forget(key string)

type Result added in v0.1.7

type Result struct {
	Val interface{}
	Err error
}

Jump to

Keyboard shortcuts

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