title: Can an existing synchronous function call be replaced with one relying on async/await?
body: <p>I am trying to replace an existing function call with one that calls out to parent frame PostMessage and receives another related PostMessage message back with a value.</p>
  <p>I am trying to have as little disruption to existing code as possible since there are a couple hundred lines where it is called.</p>
  <hr />
  <p>Current code is like the following...</p>
  <pre><code>function thisfunc(){
    return checksomethingincurrentpage()
  }
  
  if(thisfunc() == 'something')
      // do something
  
  // do something else
  </code></pre>
  <p>When switched to be based on PostMessage send/receive from parent fraome, can thisfunc() one way or another not return until the corresponding PostMessage is received and do so in the same execution path?</p>
  <p>I was trying something like this but does not look like it works. (I don't have the test code anymore)</p>
  <pre><code>//pseudocode...
  
  resolvefunc = null;
  
  function getprom()
    prom = new promise 
      set resolvingfunc equal to resolve function
    postmessagecall;
    return prom;
  
  async function thisfunc()
    response = await getprom();
    return response;
  
  eventListener for post message
    receive post message
    resolvefunc(postmessagepayload)
  
  if(thisfunc() == 'something')
    // something
  </code></pre>
  <p>I saw that XMLHttpRequest could be made to be synchronous but doesn't help in this case with PostMessage.</p>
  <p>Is this possible? How?</p>