Lines Matching full:once
28 func (once *OncePer) maybeWaitFor(key OnceKey, value interface{}) interface{} {
33 value, _ = once.values.Load(key)
35 panic(fmt.Errorf("Once() waiter completed but key is still not valid"))
42 // Once computes a value the first time it is called with a given key per OncePer, and returns the
44 // the panic will be propagated but the next call to Once with the same key will return nil.
45 func (once *OncePer) Once(key OnceKey, value func() interface{}) interface{} { func
47 if v, ok := once.values.Load(key); ok {
48 return once.maybeWaitFor(key, v)
53 if v, loaded := once.values.LoadOrStore(key, waiter); loaded {
55 return once.maybeWaitFor(key, v)
62 once.values.Store(key, v)
71 // Get returns the value previously computed with Once for a given key. If Once has not been calle…
73 func (once *OncePer) Get(key OnceKey) interface{} {
74 v, ok := once.values.Load(key)
76 panic(fmt.Errorf("Get() called before Once()"))
79 return once.maybeWaitFor(key, v)
82 // Peek returns the value previously computed with Once for a given key. If Once has not
84 func (once *OncePer) Peek(key OnceKey) (interface{}, bool) {
85 v, ok := once.values.Load(key)
90 return once.maybeWaitFor(key, v), true
93 // OnceStringSlice is the same as Once, but returns the value cast to a []string
94 func (once *OncePer) OnceStringSlice(key OnceKey, value func() []string) []string {
95 return once.Once(key, func() interface{} { return value() }).([]string)
98 // OnceStringSlice is the same as Once, but returns two values cast to []string
99 func (once *OncePer) Once2StringSlice(key OnceKey, value func() ([]string, []string)) ([]string, []…
101 s := once.Once(key, func() interface{} {
109 // OncePath is the same as Once, but returns the value cast to a Path
110 func (once *OncePer) OncePath(key OnceKey, value func() Path) Path {
111 return once.Once(key, func() interface{} { return value() }).(Path)
114 // OncePath is the same as Once, but returns the value cast to a SourcePath
115 func (once *OncePer) OnceSourcePath(key OnceKey, value func() SourcePath) SourcePath {
116 return once.Once(key, func() interface{} { return value() }).(SourcePath)
119 // OnceKey is an opaque type to be used as the key in calls to Once.
132 // objects that access the same value stored with Once.