Reputation: 75
I am currently working on a project that requires me to execute parallel processes but I can't find any way to do it in p5.js. Could someone help me with it.
Upvotes: 2
Views: 1118
Reputation: 1074198
p5 itself seems to be pretty tightly tied to the web page that you load it in, and the browser environment is such that only a single JavaScript thread can directly interact with that page. But if you have a lot of non-drawing number crunching to do, you can do that using web workers (spec | MDN). A web worker is a separate thread, isolated from the thread interacting with the web page, that can run in parallel with it and communicate with it via postMessage
and (in some environments) shared memory. (See this note on changes to shared memory to deal with Spectre and Meltdown; I also go into detail on that in my new book, JavaScript: The New Toys, in Chapter 16. Links in my profile if you're interested.)
Upvotes: 3