Source File
singleflight.go
Belonging Package
internal/singleflight
package singleflight
import
func ( *Group) ( string, func() (interface{}, error)) ( interface{}, error, bool) {
.mu.Lock()
if .m == nil {
.m = make(map[string]*call)
}
if , := .m[]; {
.dups++
.mu.Unlock()
.wg.Wait()
return .val, .err, true
}
:= new(call)
.wg.Add(1)
.m[] =
.mu.Unlock()
.doCall(, , )
return .val, .err, .dups > 0
}
func ( *Group) ( string, func() (interface{}, error)) (<-chan Result, bool) {
:= make(chan Result, 1)
.mu.Lock()
if .m == nil {
.m = make(map[string]*call)
}
if , := .m[]; {
.dups++
.chans = append(.chans, )
.mu.Unlock()
return , false
}
:= &call{chans: []chan<- Result{}}
.wg.Add(1)
.m[] =
.mu.Unlock()
go .doCall(, , )
return , true
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |