title: What is the proper way to use async/await to receive button presses without blocking in a while loop?
body: <p>I'm designing a simple browser based version of a popular game and I'm having trouble understanding how promises should be created by a button .onclick handler to deal with user input only at specific times. Here's the basic game logic:</p>
  <pre><code>&lt;button id=&quot;button1&quot;&gt;1&lt;/button&gt;
  &lt;button id=&quot;button2&quot;&gt;2&lt;/button&gt;
  &lt;script&gt;
  
  var Game = {
    ready_for_input: false,
    game_over: false,
    play_round: async function () {
  
      //do some setup, check for a few initial win conditions, then......
  
      if (round_not_yet_won) {
        ready_for_input=true;
        while (round_not_yet_won) {
          await (//somehow get a promise that is fulfilled on button click from one of two buttons)
          //when promise fulfilled by click, do some additional condition checking
          if (win) {round_not_yet_won=false; ready_for_input=false; return;} else {//go back to while loop}
  }
  }
  }
  
  while (!Game.game_over){
    Game.play_round();
  }
  
  //get buttons by id and addEventListener('click', handle_button_x())
  function handle_button_x() {//create a promise maybe?}
  
  &lt;/script&gt;
  </code></pre>
  <p>I realized while debugging previously that the reason things weren't flowing logically was that I hadn't used async/await on the while loop, so it was sporadically hanging on certain initial conditions and not letting the page send the click event. Now i realize i need to let play_round() await the button click and stop blocking so the page can do its thing, but i'm not understanding how I link up the promise both to the play_round() await structure and the handle_button_x() handler. It seems wrong to my brain to do something like this, e.g.:</p>
  <pre><code>await handle_button_x();
  </code></pre>
  <p>because this will return a promise, but it seemingly won't be linked to a button press event call of the same function. Does my failure of understanding lie in how Promise.resolve() is called maybe?</p>
  <p>Thanks for any help.</p>