@2o3t/process-manager 中文文档教程

发布于 5年前 浏览 26 项目主页 更新于 3年前

@2o3t/process-manager

Nodejs 的进程管理器。

来自 https://github.com/Microsoft/vscode 的想法。

Installation

npm install @2o3t/process-manager

yarn add @2o3t/process-manager

Usage

Client(主进程):

const PM = require('@2o3t/process-manager');
const client = new PM.Client(__dirname + '/sub-processes.js');
const channel = client.getChannel('channelName');
channel.call('info', {
    // something
}).then(data => {
    console.log('data', data);
});
channel.listen('ccc')(aa => {
    console.log('listen..', aa);
});

Server(子进程):

const PM = require('@2o3t/process-manager');
const server = new PM.Server();
const channel = new PM.ServerChannel({
    info(arg) {
        console.log('arg: ', arg);
        return Promise.resolve(server.info);
    },
    ccc(emit) {
        emit('100w');
        emit('101w');
        // server.dispose();
        emit('102w');
        emit('103w');
        emit('104w');
    },
});
console.log('server ok');
server.registerChannel('channelName', channel);

Options

Client options in paramters

modulePath< /strong>: 子进程的文件路径

options: Object.

keytypedesc
serverNamestringA descriptive name for the server this connection is to. Used in logging.
timeout?numberTime in millies before killing the ipc process. The next request after killing will start it again.
args?string[]Arguments to the module to execute.
env?anyEnvironment key-value pairs to be passed to the process that gets spawned for the ipc.
debug?numberAllows to assign a debug port for debugging the application executed.
debugBrk?numberAllows to assign a debug port for debugging the application and breaking it on the first line.
freshExecArgv?booleanSee https://github.com/Microsoft/vscode/issues/27665
* Allows to pass in fresh execArgv to the forked process such that it doesn't inherit them from process.execArgv.
* e.g. Launching the extension host process with --inspect-brk=xxx and then forking a process from the extension host results in the forked process inheriting --inspect-brk=xxx.
useQueue?booleanEnables our createQueuedSender helper for this Client. Uses a queue when the internal Node.js queue is full of messages - see notes on that method.

Server 参数中

的选项 options: 对象。

keytypedesc
timeoutDelay?numberThey will timeout after timeoutDelay.

License

麻省理工学院

@2o3t/process-manager

Process manager for Nodejs.

Ideas from https://github.com/Microsoft/vscode.

Installation

npm install @2o3t/process-manager

or

yarn add @2o3t/process-manager

Usage

Client (main process):

const PM = require('@2o3t/process-manager');
const client = new PM.Client(__dirname + '/sub-processes.js');
const channel = client.getChannel('channelName');
channel.call('info', {
    // something
}).then(data => {
    console.log('data', data);
});
channel.listen('ccc')(aa => {
    console.log('listen..', aa);
});

Server (sub process):

const PM = require('@2o3t/process-manager');
const server = new PM.Server();
const channel = new PM.ServerChannel({
    info(arg) {
        console.log('arg: ', arg);
        return Promise.resolve(server.info);
    },
    ccc(emit) {
        emit('100w');
        emit('101w');
        // server.dispose();
        emit('102w');
        emit('103w');
        emit('104w');
    },
});
console.log('server ok');
server.registerChannel('channelName', channel);

Options

Client options in paramters

modulePath: file path of sub process

options: Object.

keytypedesc
serverNamestringA descriptive name for the server this connection is to. Used in logging.
timeout?numberTime in millies before killing the ipc process. The next request after killing will start it again.
args?string[]Arguments to the module to execute.
env?anyEnvironment key-value pairs to be passed to the process that gets spawned for the ipc.
debug?numberAllows to assign a debug port for debugging the application executed.
debugBrk?numberAllows to assign a debug port for debugging the application and breaking it on the first line.
freshExecArgv?booleanSee https://github.com/Microsoft/vscode/issues/27665
* Allows to pass in fresh execArgv to the forked process such that it doesn't inherit them from process.execArgv.
* e.g. Launching the extension host process with --inspect-brk=xxx and then forking a process from the extension host results in the forked process inheriting --inspect-brk=xxx.
useQueue?booleanEnables our createQueuedSender helper for this Client. Uses a queue when the internal Node.js queue is full of messages - see notes on that method.

Server options in paramters

options: Object.

keytypedesc
timeoutDelay?numberThey will timeout after timeoutDelay.

License

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文