python-dbus-next icon indicating copy to clipboard operation
python-dbus-next copied to clipboard

Allow coroutine functions in callbacks

Open acrisci opened this issue 6 years ago • 4 comments

The high-level client on_[SIGNAL]() and low-level add_message_handler() should accept coroutine functions as handlers in addition to normal functions.

acrisci avatar May 18 '19 15:05 acrisci

Hi, i would expect a signal to be be an awaitable? Why use a callback?

e-sr avatar May 20 '19 21:05 e-sr

This is just how I do events I guess.

What would awaitable events look like? Do you have an example from another library?

acrisci avatar May 20 '19 21:05 acrisci

awaitable.

For example if looking at zmq sockets when you subscrie with a with a SUB socket to a PUB socket you await a publication

msg= await sub_socket.recv()

I expected something similar on dbus signals

signal = await bus.signal()

e-sr avatar May 21 '19 12:05 e-sr

It's easy to implement on the client side using asyncio.Queue. The callback does put_nowait and you can await on the get.