wilk / microjob

A tiny wrapper for turning Node.js worker threads into easy-to-use routines for heavy CPU loads.
https://wilk.github.io/microjob/
MIT License
2.02k stars 47 forks source link

While loop only run once inside worker thread #72

Open issadarkthing opened 3 years ago

issadarkthing commented 3 years ago

I played around with this library a bit to see how easy it is to use a worker thread. Whilst I was using it, I stumbled upon weird behavior where the while loop only run once inside the worker thread. Here is the minimal example to reproduce:

import { start, job } from "microjob";

(async () => {

  try {
    // start worker pool
    await start({ maxWorkers: 4 }); // you can also limit the available workers

    job(() => {
      while (true) {
        console.log("inside loop")
      }
    })

    // ...
  } catch (err) {
    console.error(err);
  }
})();