function onNextMessage(messagePort) {
  return new Promise(resolve => {
    function listener(event) {
      resolve(event.data);
      messagePort.removeEventListener('message', listener);
    }

    messagePort.addEventListener('message', listener);
  });
}
// |messagePort|. The event handler will then remove itself.
|messagePort|. The event handler will then remove itself.
|messagePort| . The event handler will then remove itself .
function onNextMessage(messagePort) {
  return new Promise(resolve => {
    function listener(event) {
      resolve(event.data);
      messagePort.removeEventListener('message', listener);
    }
    messagePort.addEventListener('message', listener);
  });
}
function onNextMessage ( messagePort ) { return new Promise ( resolve => { function listener ( event ) { resolve ( event . data ) ; messagePort . removeEventListener ( 'message' , listener ) ; } messagePort . addEventListener ( 'message' , listener ) ; } ) ; }
|messagePort|.
|messagePort| .