func (g *Generation) Acquire(ctx context.Context) func() {
	destroyed := atomic.LoadUint32(&g.destroyed)
	if ctx.Err() != nil {
		return func() {}
	}
	if destroyed != 0 {
		panic("acquire on destroyed generation " + g.name)
	}
	g.wg.Add(1)
	return g.wg.Done
}
Acquire creates a new reference to g, and returns a func to release that
reference.
package memoize
import (
	"context"
	"flag"
	"fmt"
	"reflect"
	"sync"
	"sync/atomic"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/xcontext"
)
var (
	panicOnDestroyed = flag.Bool("memoize_panic_on_destroyed", false,
		"Panic when a destroyed generation is read rather than returning an error. "+
			"Panicking may make it easier to debug lifetime errors, especially when "+
			"used with GOTRACEBACK=crash to see all running goroutines.")
)
type Store struct {
	mu sync.Mutex
	handles map[interface{}]*Handle
	generations map[*Generation]struct{}
}
func (s *Store) Generation(name string) *Generation {
	s.mu.Lock()
	defer s.mu.Unlock()
	if s.handles == nil {
		s.handles = map[interface{}]*Handle{}
		s.generations = map[*Generation]struct{}{}
	}
	g := &Generation{store: s, name: name}
	s.generations[g] = struct{}{}
	return g
}
type Generation struct {
	destroyed uint32
	store     *Store
	name      string
	wg sync.WaitGroup
}
func (g *Generation) Destroy() {
	g.wg.Wait()
	atomic.StoreUint32(&g.destroyed, 1)
	g.store.mu.Lock()
	defer g.store.mu.Unlock()
	for k, e := range g.store.handles {
		e.mu.Lock()
		if _, ok := e.generations[g]; ok {
			delete(e.generations, g)  
			if len(e.generations) == 0 {
				delete(g.store.handles, k)
				e.state = stateDestroyed
				if e.cleanup != nil && e.value != nil {
					e.cleanup(e.value)
				}
			}
		}
		e.mu.Unlock()
	}
	delete(g.store.generations, g)
}