NewWithError allows you to provide a lazy initializer that can fail.
(fn func() (T, error))
| 11 | |
| 12 | // NewWithError allows you to provide a lazy initializer that can fail. |
| 13 | func 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 | |
| 22 | func (v *ValueWithError[T]) Load() (T, error) { |
| 23 | result := v.inner.Load() |
no outgoing calls