Re: A Challenge Problem for Promise Designers

On Fri, Apr 26, 2013 at 1:45 PM, Domenic Denicola
<domenic@domenicdenicola.com> wrote:
> From: Tab Atkins Jr. [jackalmage@gmail.com]
>> Shorter me: this is why I keep asking people who want flattening to actually provide an example of where flattening is useful, that isn't (a) assimilation, (b) a result of weird language semantics from some non-JS language, or (c) an authoring error.
>
> Since (multi-level) flattening only occurs for assimilation (per Promises/A+ 1.1), it appears we have been talking past each other. All examples of multi-level flattening will necessarily be examples of assimilation.

In that case, HUZZAH!  We've solved the problem!  Assimilation is not
a troublesome issue; if that works best when done recursively, go for
it.  Presumably, the reason it works best when done recursively is
that if the value passed between multiple non-assimilating promise
concepts, it might have gotten multi-wrapped, once for each promise
concept (or maybe more than once for each, if the layers are separated
by other types of promises).  So, it's more useful to just assume that
multi-wrapped thenables were done accidentally, and should be fully
flattened.

If that's all we need to do, and we can have an explicit assimilation
function in the standard that takes arbitrary thenables (per the
Promises/A+ spec), then we can leave .then() alone and give it the
correct monadic semantics.  It's very difficult to accidentally get
double-wrapped within a single library with proper semantics, and
doing so indicates a fundamental logic error and so *should* give
funky results, rather than having the error accidentally papered over.

~TJ

Received on Friday, 26 April 2013 20:52:02 UTC