code: async def publish(self, subject, payload,
                        ack_handler=None,
                        ack_wait=DEFAULT_ACK_WAIT,
                        ):
          
          stan_subject = ''.join([self._pub_prefix, '.', subject])
          guid = new_guid()
          pe = protocol.PubMsg()
          pe.clientID = self._client_id
          pe.guid = guid
          pe.subject = subject
          pe.data = payload
  
          # Control max inflight pubs for the client with a buffered queue.
          await self._pending_pub_acks_queue.put(None)
  
          # Process asynchronously if a handler is given.
          if ack_handler is not None:
              self._pub_ack_map[guid] = ack_handler
  
              try:
                  await self._nc.publish_request(
                      stan_subject,
                      self._ack_subject,
                      pe.SerializeToString(),
                      )
                  return
              except Exception as e:
                  del self._pub_ack_map[guid]
                  raise e
          else:
              # Synchronous wait for ack handling.
              future = asyncio.Future(loop=self._loop)
              async def cb(pub_ack):
                  nonlocal future
                  future.set_result(pub_ack)
              self._pub_ack_map[guid] = cb
  
              try:
                  await self._nc.publish_request(
                      stan_subject,
                      self._ack_subject,
                      pe.SerializeToString(),
                      )
                  await asyncio.wait_for(future, ack_wait, loop=self._loop)
                  return future.result()
              except Exception as e:
                  # Remove pending future before raising error.
                  future.cancel()
                  del self._pub_ack_map[guid]
                  raise e
docs: Publishes a payload onto a subject.  By default, it will block
          until the message which has been published has been acked back.
          An optional async handler can be publi
  
          :param subject: Subject of the message.
          :param payload: Payload of the message which wil be published.
          :param ack_handler: Optional handler for async publishing.
          :param ack_wait: How long in seconds to wait for an ack to be received.