Angular (2+): Synchronize call to 2 methods

Discussão em 'Angular' iniciado por Zvi Vered, Março 24, 2025.

  1. Zvi Vered

    Zvi Vered Guest

    In a component (or service) I call to Main method which calls to 2 other private methods.


    export class MyService
    {
    private Stage1 ()
    {
    console.log ('-->Stage1');
    //Send dozens of HTTP requests
    console.log ('<--Stage1');
    }

    private Stage2 ()
    {
    console.log ('-->Stage2');
    //Send dozens of HTTP requests
    console.log ('<--Stage2');
    }

    public Main ()
    {
    this.Stage1 ();
    this.Stage2 ();
    }
    }

    The problem: I want that Stage2 will be called only after Stage1 is completed. The goal is to get the following output:

    -->Stage1
    <--Stage1
    -->Stage2
    <--Stage2


    Can you please advise what should I add to my code ? I tried:

    async public Main ()
    {
    await this.Stage1 ();
    await this.Stage2 ();
    }


    But this concept failed.

    Thank you, Zvika

    Continue reading...

Compartilhe esta Página