Well... there's a bigger problem afoot here. Since, in Q, resolved handlers
are called async relative to the resolution, we can have (and I've
reproduced) a situation where the second message gets dropped. This happens
in the following chain:

1. Message 1 comes in
2. Message management code calls resolve on the appropriate deferred
3. Message 2 comes in
4. Message management code calls resolve AGAIN on the first deferred
5. done handlers for the first deferred execute and install a new deferred
handle
6. Message 2 is dropped, second deferred never resolves

Concurrency is hard.


On Wed, Jan 22, 2014 at 6:19 PM, Ian Wehrman <notifications@github.com>wrote:

> In lib/generator.js:
>
> > @@ -552,38 +554,95 @@
> >                  includeAncestorMasks: settings.includeAncestorMasks || false
> >              };
> >
> > +        // Because of PS communication irregularities in different versions of PS, it's very complicated to
> > +        // know when we're "done" getting responses from executing this JSX file. In various scenarios, the
> > +        // evaluation of the JSX file produces some subset of the following responses in some *arbitrary* order:
> > +        //
> > +        // - A javascript message that is a stringification of an Action Descriptor object
> > +        //  (i.e. "[ActionDescriptor]") -- this should always come back
>
> Yes, I understand how and why you've used deferreds instead of callbacks
> for the messages responses, and I realize it would be easier in this
> particular case to have the full generality of callbacks. My suggestion is
> still to do it stupidly with deferreds instead of more generally with
> recursion. Stick a deferred in _jsMessageDeferreds that, when resolved,
> either resolves jsDeferred immediately or replaces it with a second
> deferred that will resolve jsDeferred later. The only advantage is that
> it would be manifest that there are exactly two cases. (But it still
> doesn't really matter.)
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/adobe-photoshop/generator-core/pull/135/files#r9101095>
> .
>