npm.io
5.0.0 • Published 1 year ago

qiao-process

Licence
MIT
Version
5.0.0
Deps
0
Size
5 kB
Vulns
0
Weekly
0

qiao-process

npm version npm downloads

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');

Keywords