cbitstech / Purple-Robot

Sensing and automation platform for Android.
Other
38 stars 19 forks source link

Multithreading and/or asynchronous task-processing of script code via the PurpleRobot namespace #196

Open estory1 opened 10 years ago

estory1 commented 10 years ago

There is no immediate need for the following request, but...

It would be cool (and potentially useful, for blocks of code that take an intolerably-long time) if, within the scripting layer (currently Javascript and Scheme), it were possible to instantiate threaded or asynchronous code.

Conceptually, imagine an API function like:

PurpleRobot.runInThread(scriptText)

where scriptText is the body of code to execute.

Then, the runThread call could spawn an instance of the script interpreter and execute the script (even if the language, like Javascript, does not support multithreading).

This would work for void returns (for "fire-and-forget" cases).

For non-void returns, I'm not immediately-sure what the right solution is; perhaps setting a return value for the interpreter's process exit?

As it stands, a less-efficient solution would be for the user/developer to run PurpleRobot.persist[Encrypted]String in the child thread, and PurpleRobot.fetch[Encrypted]String in the parent thread.

Foreseeable use-cases include:

audaciouscode commented 10 years ago

The only case where this makes sense is in the fire and forget scenarios. If you're doing heavy IO/CPU-bound work at the JS layer, that work should be brought into Javaland for better efficiency and control over the asynchronous concurrent processes.