forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When we share a cache amongst multiple stores, ensure it is only stop…
…ped once. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cache | ||
|
||
import "sync" | ||
|
||
type stopOnce struct { | ||
once sync.Once | ||
Cache | ||
} | ||
|
||
// StopOnce wraps a Cache and ensures its only stopped once. | ||
func StopOnce(cache Cache) Cache { | ||
return &stopOnce{ | ||
Cache: cache, | ||
} | ||
} | ||
|
||
func (s *stopOnce) Stop() error { | ||
var err error | ||
s.once.Do(func() { | ||
err = s.Cache.Stop() | ||
}) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters