« One month till Xojo.C… | Home | Xojo developer meetin… »

Multithreaded JavaScript usage

We got some interest from customers about our JavaScriptEngineMBS class and requests for better Memoryblock handling and threading. So for next prerelease of our 20.1 plugins, we include better handling of Memoryblocks. You can pass a memory block to JavaScript and receive a Memoryblock back. Either with using global properties or as parameter/result of a function or evaluate call. The data in the Memoryblock is copied and available in JavaScript as an UInt8 buffer of the matching size. We add GlobalMemoryBlock() to help you and pass a memory block which is then used by reference, so data is not copied and JavaScript can directly edit the memory from Xojo.



Combine this with our new EvaluateMT and CallFunctionMT methods and you can run various JavaScript codes on preemptive threads in the background and get all CPU cores busy. Our screenshot above shows 8 threads running the function to do the image effect 100 times.

Please makes sure the memory blocks are not released too early and you use one JavaScriptEngineMBS object per thread to keep things separated. If you access a JavaScriptEngineMBS object on two threads, we now raise an exception telling you the object is busy. Even if you use only one thread with one instance, you can keep your GUI responsive while JavaScript runs in background. Using Print and Input events or Xojo delegate method calls, it may talk to your main thread and the GUI.

Coming soon for next prerelease. Email us if you have questions or want to get early access to try it.

See also: Multithreaded plugin functions can increase speed of Xojo application, Xojo and JavaScript – A Perfect Combination, Tips for our JavaScript functions, Comparing JavaScriptEngineMBS to XojoScript and Our JavaScript engine for Xojo.
26 02 20 - 13:57