title: For Await Of not waiting for the loop to end - TypeScript / JavaScript
body: <p>In my Angular 13 program, I'm having this sync/async situation I can't resolve.
  I am calling the the <code>processLearnersInvitations</code> function that should return a promise.</p>
  <p>In that called function, I need to loop over an array of objects, and for each object perform some things, including calling two <strong>observables</strong>.</p>
  <p>Before the <code>processLearnersInvitations</code> function resolves, the loop must end and further activities on the loop results must be completed.</p>
  <p>The problem: These activities are <strong>NOT WAITING</strong> for the loop to finish (therefore successCount is always 0)..</p>
  <p>How can I make this scenario work?</p>
  <p>The called promise abbreviated:</p>
  <pre><code>processLearnersInvitations(keyHelperPerson: string, invitingPersons) {
      return new Promise(async (resolve,reject) =&gt; {
  
          for await (const invitedPerson of invitingPersons) {
              var successCounter;
              var inviteesNames;
              
              this.tgdb.runQuery('firstQuery...')
              .subscribe(
                  async result =&gt; {
                      
                      this.tgdb.runQuery('secondQuery...')
                      .subscribe(
                          async result =&gt; {
                              
                              if (...) {
                                  successCounter++;
                              } else {
                                  reject();
                              }
                              
                          });
                      
                  });
              
          } //END OF LOOP
          
          if (successCount == invitingPersons.length) {
            this.notifyInvitingLearners(invitingPersons, true);
            this.dialogs.displayToast('','Wohoo! you are now a trusted helper of ' + inviteesNames + '.', DialogType.Success);   
            resolve(1);  
          }
      
      });
  }
  </code></pre>
  <p>Calling the above function:</p>
  <pre><code>this.processLearnersInvitations(personKey, invitingPersons).then((resX) =&gt; {
    console.log('Back from processLearnersInvitations. About to route based on role: ', role);
    if ((role&gt;0)&amp;&amp;(resX==1)) {
      this.routeBasedOnRole(role);
    }
  });
  </code></pre>