I don't know if this is some kind of optimization to speed execution, or what, but it sure can bite you in the ass, since it is totally 'non-deterministic,' and seems not to be what most programmers expect. It only takes a moment to come up with the simple workaround of writing your code in the main thread to wait for a return value from the sub-function, of course, but that does feel kind of ad-hoc and crappy.
If anybody has any clue as to why this happens, I'd love to hear more -- the rationale for that design decision, or whatever technical details I'm capable of understanding.
The other irritation was caused by the way I designed some of the classes for the Scooby app -- I'd allowed some of the controller code to creep into my model (the main calender event data class), and the end result was that it completely borked the calls to the new ScoobyService methods Bobby wrote for saving calendar events.
The root of the issue turned out to be a reference to a DOM node in the data class. Ah, yes -- good ol' DOM-node references wreaking havok again. I'm still trying to figure out exactly what was going on there, but the end result was that JSON-RPC was trying to serialize something that looked like the entire DOM tree for the Scooby calendar app. When you examined the JSON object in the log, you could see huge swaths of table markup, and even form elements showing up in there.
The only thing we could figure was that DOM nodes have references to their parents, or to the main document. That's the only explanation for how all that stuff ended up in our object, because the object property was literally a single
Obviously the solution is to keep the data partitioned off from the rest of the app. Interesting to see that sometimes there actually are practical benefits to a more rigorous adherence to the MVC paradigm, instead of just that warm feeling inside that your code is 'properly' done.