function nextMessage(dataVal) {
  return new Promise((resolve) => {
    if (!nextMessageResolveMap.has(dataVal)) {
      nextMessageResolveMap.set(dataVal, []);
    }
    nextMessageResolveMap.get(dataVal)?.push(resolve);
  });
}
An implementation of nextMessage for awaiting to received messages
taken form squoosh.app