Change type of Once keys to OnceKey
Require that the key for Once calls be created with NewOnceKey
or NewCustomOnceKey.
Test: m checkbuild
Change-Id: I44b8ea6034338b45f558f862b21d5732364cbf0f
diff --git a/android/onceper.go b/android/onceper.go
index 6160506..5fefb71 100644
--- a/android/onceper.go
+++ b/android/onceper.go
@@ -26,7 +26,7 @@
// Once computes a value the first time it is called with a given key per OncePer, and returns the
// value without recomputing when called with the same key. key must be hashable.
-func (once *OncePer) Once(key interface{}, value func() interface{}) interface{} {
+func (once *OncePer) Once(key OnceKey, value func() interface{}) interface{} {
// Fast path: check if the key is already in the map
if v, ok := once.values.Load(key); ok {
return v
@@ -50,7 +50,7 @@
// Get returns the value previously computed with Once for a given key. If Once has not been called for the given
// key Get will panic.
-func (once *OncePer) Get(key interface{}) interface{} {
+func (once *OncePer) Get(key OnceKey) interface{} {
v, ok := once.values.Load(key)
if !ok {
panic(fmt.Errorf("Get() called before Once()"))
@@ -60,12 +60,12 @@
}
// OnceStringSlice is the same as Once, but returns the value cast to a []string
-func (once *OncePer) OnceStringSlice(key interface{}, value func() []string) []string {
+func (once *OncePer) OnceStringSlice(key OnceKey, value func() []string) []string {
return once.Once(key, func() interface{} { return value() }).([]string)
}
// OnceStringSlice is the same as Once, but returns two values cast to []string
-func (once *OncePer) Once2StringSlice(key interface{}, value func() ([]string, []string)) ([]string, []string) {
+func (once *OncePer) Once2StringSlice(key OnceKey, value func() ([]string, []string)) ([]string, []string) {
type twoStringSlice [2][]string
s := once.Once(key, func() interface{} {
var s twoStringSlice