non-self referencial cyclical promises?
kris.kowal at cixar.com
Wed Feb 24 19:50:54 UTC 2016
With Mark’s direction, the v2 branch of Q handles "vicious cycles" through
the WeakMap that maps promises to their underlying handler. Whenever a
promise is resolved with another promise, it walks forward through the
chain of promises that the promise handler "became" through resolution. The
first promise’s initial handler is a "vicious cycle" rejected promise
handler, so if the walk forward through the resolution returns to itself,
it remains resolved to the vicious cycle.
On Wed, Feb 24, 2016 at 11:38 AM Bradley Meck <bradley.meck at gmail.com>
> I was doing some recursive data structure work and ended up with a
> cyclical promise that did not use a direct self reference. It can be
> reduced down to:
> var af, a = new Promise(f=>af=f);
> var bf, b = new Promise(f=>bf=f);
> af(b);bf(a); // the problem
> a.then(_=>_) // some env/libs need this to start checking status
> According to https://tc39.github.io/ecma262/#sec-promise-resolve-functions
> it looks like this should cause a recursive and infinite set of
> This code currently does strange things in stable browsers, but doesn't
> seem to always cause infinite loops in the nightly builds of some things. I
> was wondering what the expected behavior is here because I am having
> trouble making sense of things.
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss