txaio icon indicating copy to clipboard operation
txaio copied to clipboard

Callback chaining clarification

Open olafmandel opened this issue 8 years ago • 3 comments

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)

olafmandel avatar Jan 04 '17 15:01 olafmandel

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 avatar Jan 04 '17 20:01 meejah

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).

meejah avatar Jan 04 '17 20:01 meejah

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')).

olafmandel avatar Jan 05 '17 08:01 olafmandel