github.com/songzhibin97/gkit@v1.2.13/cache/singleflight/singleflight.go (about)

     1  package singleflight
     2  
     3  import "golang.org/x/sync/singleflight"
     4  
     5  // SingleFlight Merge back to source
     6  type SingleFlight interface {
     7  	// Do 同步调用单飞
     8  	Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool)
     9  
    10  	// DoChan 异步调用单飞
    11  	DoChan(key string, fn func() (interface{}, error)) <-chan singleflight.Result
    12  
    13  	// Forget 可以取消已经下发未执行的任务
    14  	Forget(key string)
    15  }
    16  
    17  type Group struct {
    18  	// import "golang.org/x/sync/singleflight"
    19  	singleflight.Group
    20  }
    21  
    22  // NewSingleFlight 实例化
    23  func NewSingleFlight() SingleFlight {
    24  	return &Group{}
    25  }