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(ComputeCall<V> call, {PosComputeCall<V>? posCompute, bool resolve = true})
Creates a ComputeOnce wrapping _call.

Properties

className String
The class name of this compute implementation.
no setter
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
isResolving bool
Whether the computation is currently in progress and not yet resolved.
no setter
posCompute PosComputeCall<V>?
Optional callback invoked after the computation completes.
getter/setter pair
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
onCompute(V? value, Object? error, StackTrace? stackTrace) → void
Callback invoked when the computation completes.
resolve({bool throwError = true, FutureOr<V> onError(Object error, StackTrace stackTrace)?, V? onErrorValue}) FutureOr<V>
Resolves the computation and returns its value (V) or a Future<V>.
resolveAsync({bool throwError = true, Future<V> onError(Object error, StackTrace stackTrace)?, V? onErrorValue}) 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.
override
whenComplete(FutureOr<void> action()) Future<V>
Registers a callback to be executed when resolution completes, regardless of success or failure.
whenResolved<R>(FutureOr<R> onResolve(V? value, Object? error, StackTrace? stackTrace)) Future<R>
Invokes a callback when this value resolves, either successfully or with an error, and maps the outcome to a new result.

Operators

operator ==(Object other) bool
The equality operator.
inherited