Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about starting multiple worker threads #76

Open
andycorm opened this issue Jan 18, 2022 · 1 comment
Open

Confused about starting multiple worker threads #76

andycorm opened this issue Jan 18, 2022 · 1 comment

Comments

@andycorm
Copy link

I apologize, this is really a question and not an issue, but I can't seem to figure out if it's possible to spawn more than one worker thread using microjob.

I'm trying something like the following:

import { job, start, stop } from 'microjob';

(async () => {

  try {
    // start the worker pool
    await start();

    // this function will be executed in another thread
    const jobA = job(() => {
      console.log(`Worker ${process.pid} started`);
    });

    // this function should be executed in yet another thread
    const jobB = job(() => {
      console.log(`Worker ${process.pid} started`);
    });

    await Promise.all(jobA, jobB);

  } catch (err) {
    console.error(err);
  } finally {
    // shutdown worker pool
    await stop();
  }
})();

Every time I try something like this though, both worker threads console.log the exact same pid value. Am I doing something wrong? Or is this just a limitation with microjob?

@dillonstreator
Copy link

@andycorm microjob is using worker_threads internally so it does not deal with multiple processes. You may be confusing worker_threads with child_process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants