multiprocesstool

1.0.0 • Public • Published

multiProcessTool

nodejs 多进程函数封装

使用方法

//index.js
const MultiProcessTool = require("MultiProcessTool");
const multiProcessTool = new MultiProcessTool("worker.js");

multiProcessTool.start("hello world").then((v) => console.log(v));
//or
const multis = [
  multiProcessTool.start("hello world1"),
  multiProcessTool.start("hello world2"),
  multiProcessTool.start("hello world3"),
];
Promisse.all(multis).then((v) => console.log(v));
return datas;

// worker.js
value = process.argv[2]; //"hello world"
async function run() {
  try {
    const result = await new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(value);
      }, 1000);
    });
    process.send(result);
  } catch (error) {
    process.send(error);
  } finally {
    process.exit(0);
  }
}

run().catch(console.error);

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i multiprocesstool

      Weekly Downloads

      1

      Version

      1.0.0

      License

      Apache-2.0

      Unpacked Size

      12.9 kB

      Total Files

      4

      Last publish

      Collaborators

      • lesiyu129