qiao-process
v4.5.1
Published
nodejs process tool
Downloads
719
Maintainers
Readme
qiao-process
nodejs 下 process 能力
install
安装
npm i qiao-process
use
使用
// cjs
const { fork } = require('qiao-process');
// mjs
import { fork } from 'qiao-process';
api
fork & kill
// path
const path = require('path');
// q
const { fork, kill } = require('qiao-process');
// test
function test() {
const jsPath = path.resolve(__dirname, './cp.js');
const args = ['haha'];
const cp = fork(
jsPath,
args,
function (msg) {
console.log(`from child process: ${msg}`);
},
function (code) {
console.log(`exit code: ${code}`);
},
);
cp.send('hello child process');
// kill cp
setTimeout(function () {
kill(cp.pid);
}, 3000);
}
test();
onMsg & send
// qiao
const { onMsg, send } = require('qiao-process');
onMsg(function (msg) {
console.log(`from main process: ${msg}`);
});
send('hello main process');