Skip to content

A basic package for multithreading (multiple processes) in NodeJs

License

Notifications You must be signed in to change notification settings

vleandersson/simple-nodejs-threader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-nodejs-threader

A basic package for multithreading (multiple processes) in NodeJs

Why

To simplify node build processes, used for better development experience or to spead up build pipelines, by utilizing node's multicore processing.

Download

  • With yarn: yarn add -D simple-nodejs-threader
  • With npm: npm install simple-nodejs-threader --save-dev

Getting started

  1. Create a new Process manager
const manager = new ProcessManager("My task name");
  1. Create one or more processes that can run in parallel
const backendProcess = ProcessManager.promiseSpawn(
  "yarn start:backend",
  [processFlags],
  {
    stdio: "inherit",
    shell: true,
  }
);

const frontendProcess = ProcessManager.promiseSpawn(
  "yarn start:frontend",
  [processFlags],
  {
    stdio: "inherit",
    shell: true,
  }
);
  1. Add processes to the manager queue
manager.queue(frontendProcess, backendProcess);
  1. Await for completion
await manager.complete();

Utils

addFlags

Convert an object into Node friendly process flags.

Arguments

  • flags [Record<string, string>]

Usage

const processFlags = addFlags({ argOne: "hello", argTwo: "world" });
processFlags; // [--hello, --world]

About

A basic package for multithreading (multiple processes) in NodeJs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published