func()

in groupcache.go [455:495]


func (g *Group) check(ctx Context, key string) (ok bool, destPopulated bool, err error) {
	g.Stats.Checks.Add(1)
	viewi, err := g.loadGroup.Do(key, func() (interface{}, error) {
		// Deduplication checks - see explanation in load()
		if _, cacheHit := g.lookupCache(key); cacheHit {
			g.Stats.CacheHits.Add(1)
			return true, nil
		}
		g.Stats.ChecksDeduped.Add(1)
		var ok bool
		var err error
		if peer, ok := g.peers.PickPeer(key); ok {
			ok, err = g.checkFromPeer(ctx, peer, key)
			if err == nil {
				g.Stats.PeerChecks.Add(1)
				return ok, nil
			}
			g.Stats.PeerErrors.Add(1)
			// TODO(bradfitz): log the peer's error? keep
			// log of the past few for /groupcachez?  It's
			// probably boring (normal task movement), so not
			// worth logging I imagine.
		}
		ok, err = g.checkLocally(ctx, key)
		if err != nil {
			g.Stats.LocalCheckErrs.Add(1)
			return nil, err
		}
		g.Stats.LocalChecks.Add(1)
		destPopulated = true // only one caller of load gets this return value
		return ok, nil
	})
	if err == nil {
		var castOK bool
		ok, castOK = viewi.(bool)
		if !castOK {
			err = errors.New("groupcache: failed interface conversion")
		}
	}
	return
}