MCPcopy Index your code
hub / github.com/coder/coder / NewWithError

Function NewWithError

coderd/util/lazy/valuewitherror.go:13–20  ·  view source on GitHub ↗

NewWithError allows you to provide a lazy initializer that can fail.

(fn func() (T, error))

Source from the content-addressed store, hash-verified

11
12// NewWithError allows you to provide a lazy initializer that can fail.
13func NewWithError[T any](fn func() (T, error)) *ValueWithError[T] {
14 return &ValueWithError[T]{
15 inner: Value[result[T]]{fn: func() result[T] {
16 value, err := fn()
17 return result[T]{value: value, err: err}
18 }},
19 }
20}
21
22func (v *ValueWithError[T]) Load() (T, error) {
23 result := v.inner.Load()

Callers 4

prepareMethod · 0.92
TestLazyWithErrorOKFunction · 0.92
TestLazyWithErrorErrFunction · 0.92

Calls

no outgoing calls

Tested by 3

TestLazyWithErrorOKFunction · 0.74
TestLazyWithErrorErrFunction · 0.74