You raise an important point here.

The challenge with doing it the simple way (that you suggest) is that right now, the message management layer takes (and resolves/rejects) deferreds. The message management is abstracted away, so the higher level code isn't supposed to have to know about message IDs. In other words, there's no way for the higher level code (like this function) to register a callback that gets called every time a message with ID n comes in.

It was implemented this way because originally the communication protocol never responded with more than one message with the same ID/message type pair.

Incidentally, that limitation is why this function uses the hacky `_executeJSXFile` function.

So, the real solution is probably to use callbacks instead of deferreds at the message management layer. I've been putting off doing that, but it would greatly simplify this code. Also, I think it would make it much easier to fix another bug I'm working on.

So anyway, thanks for complaining. I'll probably make this change.