0

I was wondering if async.js can use mutliple cores (threads). The source code indicates no, but maybe I am just misinterpreting this comment:

async.parallel:

 * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
 * parallel execution of code.  If your tasks do not use any timers or perform
 * any I/O, they will actually be executed in series.  Any synchronous setup
 * sections for each task will happen one after the other.  JavaScript remains
 * single-threaded.

Is there some way to do it in multiple threads? I have some jobs that process DB entries and I need them to run all the time and on all cores.

Chris
  • 13,100
  • 23
  • 79
  • 162
  • You can find an answer here: https://stackoverflow.com/questions/39879/why-doesnt-javascript-support-multithreading – Baro Feb 17 '19 at 16:53
  • JavaScript is single threaded. With workers you can have something like child processes. But you can shared data between those processes only in a very limited way. So yes you don't have multiple javascript threads if you use `async.parallel`, the but the database adapter might issue one by one even if it didn't get the result back for the first one, so parallelisation might happens in your DB. So if the time consuming part happens in the DB then `async.parallel` could utilize multiple cores, not because javascript uses them, but because the DB does. – t.niese Feb 17 '19 at 16:54
  • You could run things in the background on it's own thread using a service worker which kind of makes it multithreaded but the things you are allowed to do is limited. – Mathias W Feb 17 '19 at 17:14

0 Answers0