[Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
Jasper St. Pierre
jstpierre at mecheye.net
Mon Oct 22 18:46:47 CEST 2012
On Sat, Oct 20, 2012 at 6:38 PM, Guido van Rossum <guido at python.org> wrote:
> On Sat, Oct 20, 2012 at 12:25 PM, Jasper St. Pierre
> <jstpierre at mecheye.net> wrote:
>> I'm curious now... you keep mentioning Futures and Deferreds like
>> they're two separate entities. What distinction between the two do you
> They have different interfaces and you end up using them differently.
Who is "you" supposed to refer to?
> In particular, quoting myself from another thread, here is how I use
> the terms:
> - Future: something with roughly the interface but not necessarily the
> implementation of PEP 3148.
> - Deferred: the Twisted Deferred class or something with very similar
> The big difference between Futures and Deferreds is that Deferreds can
> easily be chains together to create multiple stages, and each callback
> is called with the value returned from the previous stage; also,
> Deferreds have separate callback chains for regular values and errors.
Chaining is an add-on to the system and not necessarily required.
Dojo's Deferreds, modelled directly after Twisted's, don't have direct
chaining with multiple callbacks per Deferred, but instead addCallback
returns a new Deferred, which it may pass on to. This means that each
Deferred has one result, and chaining is done slightly differently.
The whole point of chaining is just convenience of mutating a value
before it's passed to the caller. It's possible to live without it.
from async_http_client import fetch_page
from some_xml_library import parse_xml
d = fetch_page(url)
d = Deferred()
page = fetch_page(url)
The two functions, treated as a black box, are equivalent. The
distinction is convenience.
> --Guido van Rossum (python.org/~guido)
More information about the Python-ideas