Finalizable
Mixin
internal
This mixin provides an asynchronous completion mechanism. This allows a process to coordinate its async actions (such as Ajax requests or user interaction) with cleanup.
Consider a context tracking helper class, for example:
class Context extends Base.mixin(Finalizable) {
// ...
async finish() {
this.owner.trigger('finish', {
context : this
});
// Wait for any scheduled finalizer to run...
await this.finalize();
}
doFinalize() {
this.destroy();
}
}
When the finish event is processed, the receiver can register a promise for whatever processing it would like to perform:
class Foo {
onFinish({ context }) {
context.finalizer = this.askUser(context);
}
async askUser(context) {
//
}
}
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Finalizable class, or subclass thereof.
-
This property can be set any time prior to calling finalize (i.e., when the isFinalizing property goes to
true). When set, this instance willawaitthis promise before completing the finalization process by calling doFinalize. -
This property is
trueonce the instance completes the finalize method. -
This property is set to
truewhen finalize is called. -
Identifies an object as an instance of Finalizable class, or subclass thereof.
Functions
Functions are methods available for calling on the class-
doFinalize( )
-
This method is called (typically by this instance or its owner) to cleanup this instance while possibly first waiting for the finalizer promise to settle. Once settled, the doFinalize method is called.