ReadinessMixin<T> mixin

Adds functionality to check and verify readiness. This usually constitutes completing some setup operation, but could also involve depending on another object's readiness and then taking an action.

Setup can be synchronous or asynchronous, which should be transparent to any code using this class.

To use ReadinessMixin in one of your classes, implement performInitialization and then, when appropriate, call markReady.

To use a class which adds ReadinessMixin, await the ready future, which returns a value of type T. T is the central object this resource produces once ready. If no such resource exists, choose void.

Synchronous usage:

class SyncResource with ReadinessMixin<SomeObject> {
  @override
  void performInitialization() {
    // Do setup...
    return SomeObject();
  }
}

// Elsewhere
final mySyncResource = SyncResource();
mySyncResource.initialize();

// Yet elsewhere
final SomeObject val = await mySyncResource.ready;

Asynchronous usage:

class AsyncResource with ReadinessMixin<SomeObject> {
  @override
  Future<SomeObject> performInitialization() async {
    // Do setup...
    return SomeObject();
  }
}

// Elsewhere
final myAsyncResource = AsyncResource();
myAsyncResource.initialize();

// Yet elsewhere
final SomeObject val = await myAsyncResource.ready;
Mixin applications

Properties

hashCode → int
The hash code for this object.
no setterinherited
isNotReady → bool
Returns true if this object has not yet successfully achieved readiness.
no setter
isReady → bool
Returns true if this object has successfully achieved readiness.
no setter
readiness ↔ Readiness
Cache of whether this object is ready. Set by the completer.
getter/setter pair
ready → Future<T>
Resolves when readiness is achieved, or immediately if it has already been achieved.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

initialize() → void
Calls performInitialization with extra bookkeeping. Descendant classes should implement performInitialization but then invoke initialize.
markReady(T obj) → void
Marks this object as ready. Implementing classes should call this function when they are ready, presumably either in or because of some side effect of performInitialization.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
performInitialization() → FutureOr<void>
Classes using ReadinessMixin should implement this method to perform any necessary initialization. Implementations of this method should call markReady and pass in any special value for T that should be returned from ready.
resetReadiness() → void
Resets any established readiness, if for example a dependency of this object has also lost readiness.
toString() → String
A string representation of this object.
inherited

Operators

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