ComputeOnce<V> class
Lazily computes a value at most once and caches either the result or error.
The computation may be synchronous or asynchronous. Subsequent calls return the cached value, rethrow the cached error, or await the in-flight Future.
If resolve is true, the computation is started eagerly.
Constructors
-
ComputeOnce(ComputeOnceCall<
V> call, {bool resolve = true}) -
Creates a ComputeOnce wrapping
_call.
Properties
- error → ({Object error, StackTrace stackTrace})?
-
Returns the cached error and stack trace if resolution failed, otherwise
null.no setter - hasError → bool
-
Whether the cached result is an error.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isResolved → bool
-
Whether the computation has completed (with value or error).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → V?
-
Returns the cached value if already resolved, otherwise
null.no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolve(
) → FutureOr< V> -
Resolves the computation and returns the value (as
V) or a Future. -
resolveAsync(
) → Future< V> - Resolves the computation asynchronously.
-
then<
R> (FutureOr< R> onValue(V value), {Function? onError}) → Future<R> - Chains a callback to the resolved value.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited