Watch 1 Star 0 Fork 0

白一梓 / local-rpcMIT

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
Nothing here. spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
readme.md

lrpc

项目源码摘自淘宝开源项目 pandora ,pandora 是一个淘宝开源的进程管理工具,里面进程间通信的模块很具有参考意义,所以将其单独分离出来做成一个项目。

安装

npm install lrpc --save

使用示例

const assert = require('assert');
const {Server,Client,util} = require('lrpc');
const msg = {
    name: 'midway-messenger',
};
const action = 'midway-messenger-action';
const sockPath = util.getRandomSocketPath();
const server = new Server({sockPath});
const client = new Client({sockPath});
new Promise(function(resolve) {
    client.ready(function() {
        resolve(client);
    });
}).then(function() {
    server.broadcast(action, msg);
    return new Promise(function(resolve) {
        client.on(action, (message) => {
            assert(message.name === msg.name);
            resolve();
        });
    });
}).then(function() {
    console.info('成功');
    assert(true);
}).catch(function() {
    assert(false);
});

在线文档

Comments ( 0 )

You need to Sign in for post a comment

Help Search