(First off, please read carefully: I understand asynchronous programming and I've done my homework. This isn't a "how do you use callbacks?" question.)
I'm working on a Javascript re-implementation of an existing software tool that was written in a synchronous/blocking I/O paradigm. Unfortunately, it involves a lot of recursive parsing that can unpredictably lead to I/O requests. So there are certain functions that I'd really, really like to just spin while the I/O happens. That is, I want to write something like this:
function super_duper_nested () {
... oh crap I need to wait for an I/O result
while (runtime.eventsPending ())
runtime.processEvents ()
... grab result and continue
}
But, as far as I can tell, this just isn't available in standard Javascript environments. Is that really the case? Are there any sneaky ways to pause my control flow and let events get processed for a bit?
I've read some things about "synchronous events" in browsers that seem relevant, but my impression is that it's unlikely that I can wire them into this complicated application in a sane way.
Finally, Firefox does appear to have a DebuggerServer.xpcInspector.enterNestedEventLoop interface that might do exactly what I want. But with a name like that, it is not something that I'm willing to embed in production code. (Besides the whole thing of wanting my code to work on platforms other than Firefox.)