Ejemplo n.º 1
0
    def send_and_get_reply(self, message, *, timeout=None, unwrap=None):
        """Send a message, wait for the reply and return it

        Filters are applied to other messages received before the reply -
        see :meth:`add_filter`.
        """
        check_replyable(message)
        deadline = timeout_to_deadline(timeout)

        if unwrap is None:
            unwrap = self._unwrap_reply

        serial = next(self.outgoing_serial)
        self.send_message(message, serial=serial)
        while True:
            msg_in = self.receive(timeout=deadline_to_timeout(deadline))
            reply_to = msg_in.header.fields.get(HeaderFields.reply_serial, -1)
            if reply_to == serial:
                if unwrap:
                    return unwrap_msg(msg_in)
                return msg_in

            # Not the reply
            self.router.incoming(msg_in)
            for filter in self._filters.matches(msg_in):
                filter.queue.append(msg_in)
Ejemplo n.º 2
0
 async def send_message(self, message: Message):
     if (
             message.header.message_type == MessageType.method_return
             and not (message.header.flags & MessageFlag.no_reply_expected)
     ):
         return unwrap_msg(await self.send_and_get_reply(message))
     else:
         await self.send(message)
Ejemplo n.º 3
0
 def inner(*args, **kwargs):
     timeout = kwargs.pop('_timeout', self._timeout)
     msg = make_msg(*args, **kwargs)
     assert msg.header.message_type is MessageType.method_call
     reply = self._router.send_and_get_reply(msg, timeout=timeout)
     return unwrap_msg(reply)
Ejemplo n.º 4
0
 async def inner(*args, **kwargs):
     msg = make_msg(*args, **kwargs)
     assert msg.header.message_type is MessageType.method_call
     return unwrap_msg(await self._router.send_and_get_reply(msg))