Skip to content

Commit

Permalink
Merge pull request #87 from ydirson/async-callbacks
Browse files Browse the repository at this point in the history
Support coroutines as signal handlers (#2)
  • Loading branch information
acrisci committed Jul 4, 2021
2 parents b70121a + 32a6e3f commit 7d651b6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dbus_next/proxy_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from .errors import DBusError, InterfaceNotFoundError
from ._private.util import replace_idx_with_fds

from typing import Type, Union, List
from typing import Type, Union, List, Coroutine
import logging
import xml.etree.ElementTree as ET
import inspect
import re
import asyncio


class BaseProxyInterface:
Expand Down Expand Up @@ -97,7 +98,9 @@ def _message_handler(self, msg):

body = replace_idx_with_fds(msg.signature, msg.body, msg.unix_fds)
for handler in self._signal_handlers[msg.member]:
handler(*body)
cb_result = handler(*body)
if isinstance(cb_result, Coroutine):
asyncio.create_task(cb_result)

def _add_signal(self, intr_signal, interface):
def on_signal_fn(fn):
Expand Down

0 comments on commit 7d651b6

Please sign in to comment.