class Google::Cloud::Env::LazyValue

@private

A lazy value box with thread-safe memoization. The first time accessed it will call a given block to compute its value, and will cache that value. Subsequent requests will return the cached value.

At most one thread will be allowed to run the computation; if another thread is already in the middle of a computation, any new threads requesting the value will wait until the existing computation is complete, and will use that computation’s result rather than kicking off their own computation.

If a computation fails with an exception, that exception will also be memoized and reraised on subsequent accesses. A LazyValue can also be configured so subsequent accesses will retry the computation if the previous computation failed. The maximum number of retries is configurable, as is the retry “interval”, i.e. the time since the last failure before an access will retry the computation.

By default, a computation’s memoized value (or final error after retries have been exhausted) is maintained for the lifetime of the Ruby process. However, a computation can also cause its result (or error) to expire after a specified number of seconds, forcing a recomputation on the next access following expiration, by calling {LazyValue.expiring_value} or {LazyValue.raise_expiring_error}.

We keep this private for now so we can move it in the future if we need it to be available to other libraries. Currently it should not be used outside of Google::Cloud::Env.