Skip to content

MessageBus.add_message_handler:Support coroutine functions in callbacks. #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions dbus_next/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import logging
import xml.etree.ElementTree as ET
import traceback

from typing import Type, Callable, Optional, Union
import asyncio
from typing import Type, Callable, Optional, Union, Coroutine


class BaseMessageBus:
Expand Down Expand Up @@ -665,8 +665,10 @@ def _process_message(self, msg):

for handler in self._user_message_handlers:
try:
result = handler(msg)
if result:
result = handler(msg)
if isinstance(result, Coroutine):
asyncio.create_task(result)
elif result:
if type(result) is Message:
self.send(result)
handled = True
Expand Down