Closed jschlyter closed 3 years ago
Are you talking about the code in dali.drivers.hid
? If so, callbacks are made using the call_soon()
method of the event loop. If you want to execute async code from the callback, you should be able to use create_task()
in the normal way.
(Arguably the code that makes the callback ought to be able to spot that the target is a coroutine and call create_task()
itself; I'll consider that for the future.)
So something like this should work?
def callback(*args, **kwargs):
await asyncio.create_task(async_callback(*args, **kwargs))
Except without the "await": you're creating a new task, not waiting for a coroutine to complete.
Works, thanks a lot!
Is there any way to create async callbacks, e.g., that the function provided to
register()
is async? Or is callbacks always sync?cc @fredriklj