A pattern for asynchronous object initialization and cleanup of a target object, called the "subject".
Construction happens in the initializer parameter of Construction or via Construction.construct on
the subject. You invoke in your constructor and place in a property called "construction".
Destruciton is optional and happens in the destructor parameter of Construction#close or via
Construction.destruct on the subject. Typically you invoke in a "close" method of the subject.
If construction or destruction is not asynchronous (does not return a Promise) then they complete synchronously,
including throwing exceptions.
To ensure an instance is initialized prior to use you may await construction, so e.g. await new MyConstructable().construction. asyncNew is shorthand for this. The creation code path can instead await
Construction.ready to ensure handling of the root cause.
Public APIs should provide a static async create() that performs an asyncNew(). The class will then adhere to
Matter.js conventions and library users can ignore the complexities associated with async creation.
A pattern for asynchronous object initialization and cleanup of a target object, called the "subject".
Construction happens in the initializer parameter of Construction or via Construction.construct on the subject. You invoke in your constructor and place in a property called "construction".
Destruciton is optional and happens in the destructor parameter of Construction#close or via Construction.destruct on the subject. Typically you invoke in a "close" method of the subject.
If construction or destruction is not asynchronous (does not return a Promise) then they complete synchronously, including throwing exceptions.
To ensure an instance is initialized prior to use you may await construction, so e.g.
await new MyConstructable().construction
. asyncNew is shorthand for this. The creation code path can instead await Construction.ready to ensure handling of the root cause.Public APIs should provide a static async create() that performs an asyncNew(). The class will then adhere to Matter.js conventions and library users can ignore the complexities associated with async creation.