mozilla/r2d2b2g — pull request #662 by mykmelez (2013-06-26 23:43:53+00:00)
Title: install app on connect to app if app isn't already installed

This changeset makes the new "connect to app" functionality install the app while connecting to it if it isn't already installed.

It does this by making *simulator.runApp* a fully round-trip operation that calls its *next* callback with an error if the app isn't already installed. Then it makes *simulator.connectToApp* call *simulator.runApp* with a callback that calls *simulator.updateApp* and then *simulator.runApp* again if it receives an *app-not-installed* error.

Along the way I simplified some code in *simulator.runApp* and the actor script. But mostly I made the code more complex, because the code in question uses callbacks to chain asynchronous functions, which quickly becomes complex when you actually start to handle error cases instead of silently ignoring them. In the long run, we should move this code to promises to make error handling of complex asynchonous function chains simpler.