named-data / python-ndn

An NDN client library with AsyncIO support in Python 3
https://python-ndn.readthedocs.io/en/latest
Apache License 2.0
24 stars 17 forks source link

app: Add async support for callback #43

Closed GlassyYang closed 2 years ago

GlassyYang commented 2 years ago

python-ndn is writen by coroutine, but app doesn't support async function register, which means if a user-registered callback function is a timing consuming operation, it will still block everything. under this situation, async callback register is extreamily useful.

zjkmxy commented 2 years ago

See #16 This design is on purpose: the producer must respond to the Interest first before it performs any operation that takes time.

GlassyYang commented 2 years ago

Should we ensure whether interest is not expired or not like this way: we just sleep a certain time, and cancel the task when it is still running. with async function, we can tell user their callback takes too long rather than let user debug and find this problem by themself.

zjkmxy commented 2 years ago

You can use create_task to do whatever you want. There is no need to modify the library. An async callback delays not only this packet but also blocks all future packets.

GlassyYang commented 2 years ago

That's remind me. Thank you very much.