github.com/sequix/cortex@v1.1.6/pkg/chunk/cache/stop_once.go (about)

     1  package cache
     2  
     3  import "sync"
     4  
     5  type stopOnce struct {
     6  	once sync.Once
     7  	Cache
     8  }
     9  
    10  // StopOnce wraps a Cache and ensures its only stopped once.
    11  func StopOnce(cache Cache) Cache {
    12  	return &stopOnce{
    13  		Cache: cache,
    14  	}
    15  }
    16  
    17  func (s *stopOnce) Stop() error {
    18  	var err error
    19  	s.once.Do(func() {
    20  		err = s.Cache.Stop()
    21  	})
    22  	return err
    23  }