I have a function:
async ready():Promise<boolean> {
await this.myClass.firstToComplete();
this.myClass.secondToComplete();
}
However, firstToComplete()
needs to wait for an event it is listening for before proceeding.
async firstToComplete(): Promise<void>{
return new Promise(resolve => this.anEventListener = () => resolve());
}
Yet, I'm unsure of how to properly structure this in my code.
Here is an overview of my current codebase:
async ready():Promise<boolean> {
await this.myClass.firstToComplete();
this.myClass.secondToComplete();
}
export class myClass{
private static completion_event = new Event("complete");
async anEventListener(): Promise<void>{
await window.addEventListener("complete", function(){
return
});
}
async firstToComplete(): Promise<void> {
await this.listening();
async listening() {
return new Promise(resolve => this.anEventListener = () => resolve());
}
private static functionWaitingToComplete() {
window.dispatchEvent(this.completion_event)
}