non-self referencial cyclical promises?

Kris Kowal kris.kowal at
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>

> 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:
> ```javascript
> 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
> it looks like this should cause a recursive and infinite set of
> `EnqueueJob("PromiseJobs",...)`
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list