🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

promise-process-pool

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-process-pool

A promise based process pool

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

promise-process-pool 基于 promise 的进程池实现

NPM

NPM version Build Status

Usage

默认启动的子文件为 ./subProcess.js 在进程中默认的函数为 main

"use strict";
const Pool = require("promise-process-pool");
let tasks1=[1,2,3,4,5];
// fork(./subProcess.js) 
// 并将 task1 传入 subProcess.js 中的 main 函数
var p = new Pool() 
p.run(tasks1).then(arr=>{
    console.log(arr);
});

也可以自定义进程池函数

// 进程池上线为 8
// fork(./sub.js) 
// 并将 task1 传入 sub.js 中的 myMethod 函数
var p = new Pool(8,"./sub.js","myMethod") 
p.run(tasks1).then(arr=>{
    console.log(arr);
});

规定, 一个子进程 send 出来的消息必须携带 err 字段 这里提供一个模板

subProcess.js:

let subProcess = {}

subProcess.main = function (task) {
    process.send({ err: false, task: task });
}

process.on('message', info => {
    subProcess[info.method](info.task) // info.method 为父进程传递进来的 method 参数
});

Keywords

process

FAQs

Package last updated on 14 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts