title: Wait for async function to return a value in Typescript.
body: <p>I have a function (Function1) that calls another function (Function2) that returns a string. </p>
  
  <p>I want Function1 to call Function2, but wait and get the return value of Function2. How do you go about doing that? Here's my code (which does not work as intended):</p>
  
  <p>Here is my Function1:</p>
  
  <pre><code>async Function1() {
      const message = await this.dialogButtonPress();
      alert(message);
  }
  </code></pre>
  
  <p>Here is my Function2:</p>
  
  <pre><code>async dialogButtonPress() : Promise&lt;string&gt; {
      const doneButtonPromise = new Promise((resolve) =&gt; {
          const doneButton = document.getElementById("done-button");
          const resolver = () =&gt; {
              resolve();
              doneButton.removeEventListener("click", resolver);
          }
          doneButton.addEventListener("click", resolver);
      });
  
      const cancelButtonPromise = new Promise((resolve) =&gt; {
          const cancelButton = document.getElementById("cancel-button");
          const resolver = () =&gt; {
              resolve();
              cancelButton.removeEventListener("click", resolver);
          }
          cancelButton.addEventListener("click", resolver);
      })
  
      doneButtonPromise.then(() =&gt; {
          console.log("DONE BUTTON PRESSED!");
          return "Confirm";
  
      });
  
      cancelButtonPromise.then(() =&gt; {
          console.log("CANCEL BUTTON PRESSED!");
          return "Cancel";
      });      
  }
  </code></pre>