Promise for request/response with timeout
await is only applicable in async functions. The executor function passed to Promise constructor at the code at the question is not defined as async. 

The second Promise constructor is not necessary. resolve and reject defined at the single Promise executor can be used.

Include .catch() or function at second parameter of .then() chained to Promise constructor to avoid Uncaught in Promise error and handle potential error within Promise constructor function body.

new Promise((resolve, reject) =&gt; {
  try {
    const complete = () =&gt; !clearTimeout(time) 
      &amp;&amp; this.removeListener(listener);
    const listener = ({command}) =&gt; command === "pong" 
      &amp;&amp; !complete() &amp;&amp; resolve();
    this.addListener(listener);
    this.sendMessage({ command: "ping" });
    const time = setTimeout(() =&gt; !complete() &amp;&amp; reject(), timeout);
  } catch (e) {
      throw e
  }
})
// handle resolved `Promise`, handle error
.then(() =&gt; {}, e =&gt; console.error(e));