feat: speed up checking if a message needs a reply (#181)

This commit is contained in:
J. Nick Koston 2022-12-08 16:10:16 -10:00 committed by GitHub
parent 932053b903
commit d1366aca64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -10,9 +10,12 @@ cdef object MessageFlag
cdef object MESSAGE_TYPE_CALL
cdef object MESSAGE_TYPE_SIGNAL
cdef object NO_REPLY_EXPECTED_VALUE
cdef object assert_object_path_valid
cdef object assert_bus_name_valid
cdef _expects_reply(Message msg)
cdef class SendReply:
cdef object _bus

View File

@ -27,6 +27,11 @@ from .validators import assert_bus_name_valid, assert_object_path_valid
MESSAGE_TYPE_CALL = MessageType.METHOD_CALL
MESSAGE_TYPE_SIGNAL = MessageType.SIGNAL
NO_REPLY_EXPECTED_VALUE = MessageFlag.NO_REPLY_EXPECTED.value
def _expects_reply(msg) -> bool:
return not (msg.flags.value & NO_REPLY_EXPECTED_VALUE)
class SendReply:
@ -43,10 +48,8 @@ class SendReply:
return self
def __call__(self, reply: Message) -> None:
if self._msg.flags & MessageFlag.NO_REPLY_EXPECTED:
return
self._bus.send(reply)
if _expects_reply(self._msg):
self._bus.send(reply)
def _exit(
self,
@ -753,7 +756,7 @@ class BaseMessageBus:
self._name_owners[msg.destination] = reply.sender
callback(reply, err) # type: ignore[misc]
no_reply_expected = msg.flags & MessageFlag.NO_REPLY_EXPECTED
no_reply_expected = not _expects_reply(msg)
# Make sure the return reply handler is installed
# before sending the message to avoid a race condition