title: Angular / TypeScript - Call a function after another one has been completed
body: <p>I would like to call <code>f2</code> after <code>f1</code> has been completed. <code>f1</code> function can be <strong>synchronous</strong> or <strong>asynchronous</strong>. I need an example that work in both cases. I have found a solution, using a <code>Promise</code> and a timer: </p>
  
  <pre><code>global() {
      this.f1().then(res =&gt; {
          this.f2()
      })
  }
  
  f1() {
      return new Promise&lt;any&gt;((resolve, reject) =&gt; {
  
          // Some code...
  
          setTimeout( () =&gt; {
              resolve(x);
          }, 1500);
      });
  }
  
  f2() {
      // Some code...
  }
  </code></pre>
  
  <p>The problem is the program always have to wait <strong>1500ms</strong>. I don't want <code>f2</code> start before <code>f1</code> is finished.
  Is there a way to wait the time needed, not more or less?</p>