title: Await a promise multiple times in parallel
body: <p>I have some server API methods I call during startup of my application at different places, which can't be refactored in terms of where they are called, let's say <code>getSettings()</code> and <code>getSchedule()</code>. Both methods are based on a <code>login(): Promise&lt;Account&gt;</code> method as settings as well as the schedule are user-based.</p>
  <p>Now I have solved the beginning of <code>getSettings()</code> and <code>getSchedule()</code> like the following:</p>
  <pre><code>class UserFunctions {
      private fetch_login: Promise&lt;AccountItem&gt; = undefined;
      async getSchedule(): Promise&lt;any&gt; {
          var account = getAccount();
          if (!account) {
              // No account loaded
              let isLogginIn = this.fetch_login;
              if (!this.fetch_login) {
                  // Not logging in from any parallel method
                  this.fetch_login = login();
              }
              account = await this.fetch_login;
              this.fetch_login = undefined;
          }
          
          // Now get schedule...
      }
  }
  </code></pre>
  <p>The idea behind is that the <code>login()</code> function is only called once no matter how often it could be called. That's why I keep a reference on the Promise to await it multiple times. This works, but I noticed that sometimes when <code>login()</code> is done <code>getSettings()</code> gets earlier the okay to continue work and <code>getSchedule()</code> stays a few seconds until it continues executing. Sometimes it's the other way around and sometimes both methods return in the same time.</p>
  <p>Here I have a print of the output:</p>
  <blockquote>
  <p>06-05 16:46:08.126 27376 27397 I ReactNativeJS: Logging in back</p>
  <p>06-05 16:46:08.690 27376 27397 I ReactNativeJS: Logged in back</p>
  <p>06-05 16:46:08.696 27376 27397 I ReactNativeJS: Schedule downloaded</p>
  <p>06-05 16:46:09.274 27376 27397 I ReactNativeJS: Logged in back</p>
  </blockquote>
  <p>Do you have any idea how the code can be improved that once <code>login()</code> is done, both methods continue working?</p>