I currently using async/await method and that's helpful with https requests but doesn't help with synchronous code.
What can I do to improve performance in that case?
Can I use something like nested worker threads?
I can use worker threads in the last functions but I want to be able to use them in nested mode!
Is it possible to do something like that in javascript/node.js or I have to switch language/platform!?
Code example:
(async(){
/*Some code*/
let Items=[]; //Long array
for(let Item in Items){
(async(){
/*Some code*/
let Items=[]; //Long array
for(let Item in Items){
(async(){
//And so on ...
})();
}
/*Wait until all functions done*/
/*Some code*/
})();
}
/*Wait until all functions done*/
/*Some code*/
})();
Best answer until now: Using shared resources between threads, Because threads can't run in nested mode (making a tree/within each other)!
Yes, code can use something like Node.js Worker threads to allow parallelism for CPU-bound work.
Workers (threads) are useful for performing CPU-intensive JavaScript operations. They do not help much with I/O-intensive work. The Node.js built-in asynchronous I/O operations are more efficient than Workers can be.
The async concurrency model is still used and each execution context is single-threaded.
The worker threads are themselves running in separate execution contexts and, conceptually in context of await (eg. of promise wrappers around the events), using worker threads is little different than using XHR to dispatch processing to remote compute servers.
Unlike more direct multithreaded support in other languages, this also comes with the restriction that objects are not implicitly shared between the node app and any worker threads, as they are not shared in remote XHR work. Code will need to be written to appropriately divide data and join results or otherwise marshal through a shared resource (eg. filesystem or SharedArrayBuffer).