A new writable ICachedValue instance which wraps the callback and will be used to cache the result of the callback
// This does not cause the evaluation to occur
let cachedValue = safeGetWritableDeferred(
() => JSON.parse(potentiallyInvalidJson),
{ defaultValue: true }
);
// With arguments
let cachedValueWithArgs = safeGetWritableDeferred(
(id, name) => fetchDataThatMightFail(id, name),
{ defaultValue: "Not Found" },
[123, "test"]
);
// This will cause the evaluation to occur and the result will be cached
// If the evaluation throws, the default value will be returned
let theValue = cachedValue.v;
// The cached value can be changed
cachedValue.v = { newValue: true };
Create and return a writable ICachedValue instance which will cache and return the value returned by the callback function. The callback function will only be called once, multiple access of the value will not cause re-execution of the callback as the result from the first call is cached internally. If the callback throws the default value will be returned. Unlike safeGetDeferred, this version allows the cached value to be changed after it's been evaluated. This is a lightweight version that does not support any expiration or invalidation.