On Sat, Jul 8, 2023 at 6:42 AM Daniil Kustov <dan.kus...@gmail.com> wrote: > > 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: > > 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. > Using v8::TryCatch and TerminateExecution. > Using the v8 debugging API to suspend the script by the "debugger" > > > Also, I tried to write my own implementation v8::Platform, but v8 still > executes javascript code synchornously(blocking current thread)
You could call isolate->RequestInterrupt() and run your event loop from the interrupt callback but then you can't call back into JS code. If that doesn't work for you, then only option 2 - TryCatch and TerminateExecution - remains. -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/CAHQurc_kuPX-sgpH92CmNS%2BsZDijSWQncbXU5bcsCmMfV9njKg%40mail.gmail.com.