On Fri, 30 Nov 2012 11:04:09 -0800 Guido van Rossum <guido@python.org> wrote:
Futures or callbacks, that's the question...
Richard and I have even been considering APIs like this:
res = obj.some_call(<args>) if isinstance(res, Future): res = yield res
or
res = obj.some_call(<args>) if res is None: res = yield <magic>
where <magic> is some call on the scheduler/eventloop/proactor that pulls the future out of a hat.
The idea of the first version is simply to avoid the Future when the result happens to be immediately ready (e.g. when calling readline() on some buffering stream, most of the time the next line is already in the buffer); the point of the second version is that "res is None" is way faster than "isinstance(res, Future)" -- however the magic is a little awkward.
This premature optimization looks really ugly to me. I'm strongly -1 on both idioms. Regards Antoine.