Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback chaining clarification #86

Open
olafmandel opened this issue Jan 4, 2017 · 3 comments
Open

Callback chaining clarification #86

olafmandel opened this issue Jan 4, 2017 · 3 comments

Comments

@olafmandel
Copy link

The documentation states:

Note that txaio doesn’t do anything special with regards to callback or errback chaining – it is highly recommended that you always return the incoming argument unmodified in your callback/errback so that Twisted and asyncio behave the same.

But even for asyncio there is a slightly hacky call-chaining implemented in txaio/aio.py. And this seems to be used extensively, e.g. in autobahn/wamp/protocol.py.

Please either update the documentation, rendering this functionality "official and supported" or remove the hack from aio.py (which I expect to cause quite some test failures in dependent libraries). If the decision is to remove the hack, please consider providing a replacement for this idiom used in crossbario/autobahn-python:

d = txaio.as_future(func1)
txaio.add_callbacks(d, txaio.as_future(func2), None)
txaio.add_callbacks(d, txaio.as_future(func3), None)
@meejah
Copy link
Contributor

meejah commented Jan 4, 2017

Okay, I think the sane thing to do here is to keep the "hack" and document it. This basically makes the callback-value-chaining work the same way as Twisted. Do you foresee any problems with this for asyncio users?

@meejah
Copy link
Contributor

meejah commented Jan 4, 2017

Also, the recommendation in the docs should still be to always return the incoming arg (i.e. to not depend on mutating the return-values in your library).

@olafmandel
Copy link
Author

Do you foresee any problems with [rendering the hack official] for asyncio users?

I am just getting started with async programming in Python (which is why I actually read the docs and found this...), so I am not the best person to ask.

Having said that, it seems that asyncio.Future()._result is an undocumented internal, which may be changed at any time. So maybe add some check like assert(hasattr(f, '_result')).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants