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: make register() work when app first starts up #10

Closed JonnyKong closed 4 years ago

JonnyKong commented 4 years ago

Currently, if app.register() is called before the tcp face is ready, it causes the error NetworkError: cannot send packet before connected.

In some cases, this forces users to abuse the use of app.route(), for example:

https://github.com/JonnyKong/ndn-python-repo/blob/37ba6b9e754eff04581f8b8b8afa30b40255fb65/ndn_python_repo/handle/write_command_handle.py#L42-L48

zjkmxy commented 4 years ago

This is designated behavior. If register() works before it is connected, there is no need for route() function.

JonnyKong commented 4 years ago

This is designated behavior. If register() works before it is connected, there is no need for route() function.

Do you mean you intend users to use route(), even if it's not called in a decorator-style?

zjkmxy commented 4 years ago

This is designated behavior. If register() works before it is connected, there is no need for route() function.

Do you mean you intend users to use register(), even if it's not called in a decorator-style?

Yes. However, for your code, why not just make _on_insert_interest() nested functions? I don't think other parts of your program needs to call it directly. If they do, write the implementation function outside and write a wrapper function handling the content decoding inside.