kin4stat
kin4stat

Reputation: 322

Embedding V8 into an existing mainloop

I'm trying to embed V8 into an existing code that already has a mainloop.

As I understand it, script->Run() is executed before the script finishes executing its "main body" (global scope).

The main problem is that in this case my mainloop will hang until the script is executed(My application is single-threaded). Executing scripts in a separate thread also does not look like a good solution, because for each API call of my application from the script, I will have to synchronize the mainloop and the script thread, which in the end can greatly affect the performance and quality of the code.

Also, it would be nice if it was possible to forcibly suspend the execution of JS from the script itself (for example, with the yield function)

Here are the "crutch" solution ideas that are currently available, but they feel terrible:

  1. Creating Fibers for each script, and switching them with the main thread. But in this case, it seems to me that I will break a lot of mechanisms inside the engine.
  2. Using v8::TryCatch and TerminateExecution.
  3. Using the v8 debugging API to suspend the script by the "debugger"

Upvotes: 0

Views: 141

Answers (0)

Related Questions