Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to call a function after promise

JavaScript noobie here. Lacking knowledge of an important design pattern.

this.getEventData(); < How can I call that function after the promise is resolved? So then I can remove the noobie setTimeout ?

  public onInit(): Promise<void> {
    return super.onInit().then(_ => {
      new Promise<void>((resolve: () => void, reject: (error: any) => void): void => {
        this.context.aadHttpClientFactory
          .getClient(APIAppRegID)
          .then((client: AadHttpClient): void => {
            this.httpClient = client;
            resolve();
          }, err => reject(err));
      });
      setTimeout(() => {
        this.getEventData();
      }, 1500);
    });
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

async/await version :

async onInit(): Promise<void> {
  await super.onInit();
  this.httpClient = await this.context.aadHttpClientFactory.getClient(APIAppRegID);
  this.getEventData();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading