robertkrimen / otto

A JavaScript interpreter in Go (golang)

Home Page:http://godoc.org/github.com/robertkrimen/otto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How would you add parallel execution?

RudolfVonKrugstein opened this issue · comments

Thanks for the great project!

I am currently evaluating otto to use as a scripting language for a simple application that executes small scripts on events (the events are button presses on a elgato stream deck).

It works very well so far!

In general the scripts are very short and can be executed one after the other, but I also want to have longer running processes, like starting a countdown. And while these processes runs, it should be possible to press other buttons and start other processes in parallel.

Now I am thinking about how to approach that, and maybe someone with experience with otto would be so kind to give me some advice?

Here are my ideas:

  1. Create a go routine and a otto VM for every button press and execute the buttons script in that VM. Is that a good Idea? I also need some simple mechanism for global variables, but I could add functions (setGlobal, getGlobal) to the VM to have this functionality.
  2. Create a go routine for every button but reuse one otto VM. I tried that, it works. But I guess that is not intended usage and might introduce all sorts of unexpected bugs.
  3. Implement an event loop (like in http://github.com/robertkrimen/natto). This is my favorite option. But since otto does not support await/async syntax, this makes the script harder to write for inexperienced script writers and I want to keep the writing of the scripts as simple as possible.

So I am hoping I am not rude by asking for advice. And thanks for again this great project and all the work that went into it.

All of the options you have listed sound reasonable, but this is really for issues not advice on use, I suggest you use https://stackoverflow.com/ for that.