OpenCyphal / pycyphal

Python implementation of the Cyphal protocol stack.
https://pycyphal.readthedocs.io/
MIT License
119 stars 106 forks source link

Support non-async subscription callbacks #167

Closed pavel-kirienko closed 2 years ago

pavel-kirienko commented 3 years ago

See Subscriber.receive_in_background(..): currently, it expects the handler to be async, which is rarely necessary. The library should also accept synchronous handlers. The implementation should be trivial --- just call the handler using the synchronous syntax and check if the result is an Awaitable[]; if so, await on it, otherwise do nothing:

https://github.com/UAVCAN/pyuavcan/blob/4ec55a80f8fd3dd21a3d08102837c43d832b71a3/pyuavcan/presentation/_port/_subscriber.py#L104-L110

The same logic might also work for Server.serve(..) et al.