title: Typescript. wait a code to executing until a function finish executing
body: <p>I have a code that calls a function as shown below:</p>
  
  <pre><code>this.getAllOptions(questionID);
  console.log("++++++++++++++++++++++++++++++++");
  console.log(this.result);
  </code></pre>
  
  <p>the function is very simple, it calls a service that returns an array of object. From the returned data, I only need the "item.Content" in a string format, as shown below.  </p>
  
  <pre><code>result: string;
  getAllOptions(question_ID){
  
      this.result = "";
  
      this._service.getOptionsQuestion(question_ID)
          .subscribe( data =&gt; {
              data.forEach(item =&gt; {
              console.log(item.Content);
              this.result += item.Content;
              });
          });
  }
  </code></pre>
  
  <p>But the problem is, the codes after calling the function "getAllOptions()" get executed first.  I want the codes after calling the methods to wait until function done executing. </p>
  
  <p>Is that possible?</p>