CodeCoupler UI Async Contructor Pattern
This class is uesed internally. Normally you never have to use this.
Classes derived from here can initiated with
1 |
|
Or with:
1 2 |
|
Classes derived from here have to implement their asynchronous initialisation procedure within an method "init":
1 2 3 4 5 |
|
You can implement an additional method async prepare
if you need to do things before init
is
called. Depending on the return value the following action will be taken:
- If you return here
false
,init
will not be executed. - If you return something different from
true
the theinitialized
resolves to this returned value andinit
will not be executed. So aawait x = new Something().initialized
will result to this value as new instance.
Please keep in mind, that if you use a prepare
method that could eventually return another
instance you should instruct the users to reassign the variable if not using the oneliner:
1 2 |
|
The first line would just return a new instatiated class, but the second line would return the instance you have specified with the method "prepare".