Closed mfikes closed 9 years ago
Had a discussion on IRC with the resulting sentiment: Perhaps it need not be on another thread for development purposes.
JSContext
is thread safe. Its hosting JSVirtualMachine
will serialize calls from different threads using locking/mutexes as needed.
So the concept of JSContext
being on another thread is ill defined. It is really where the calls are coming from. ReactNative sets things up so that calls originate from the dedicated thread it sets up. But, there is really nothing wrong with REPL calls also coming in on other threads (even the main thread). If a long-running REPL evaluation is done from the main thread, it will simply block the UI for a bit.
Looked at another way, we are actually already in good shape and can eliminate some of the thread-affinity assertions sprinkled in the Ambly code.
Currently Ambly simply creates a context on the main thread, and all TCP messaging with the REPL is also done on the main thread.
Frameworks like React Native want the JSContext to be on a background thread, and if you look at
RCTContextExecutor
you can see that it sets up an event dispatch thread loop. This could perhaps be supported by abstracting over how Ambly sends stuff into the JSContext to be evaluated (so that the app can cause REPL calls to simply be redirected to React Native'sRCTContextExecutor
, for example).