New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

worker-communication

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worker-communication

This module provide bilateral communication with callback between cluster worker and master, node.js child process is supported too.

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

worker-communication

This module provide bilateral communication with callback between cluster worker and master, node.js child process is supported too.

Installation

npm i worker-communication

Usage

Master

import CPC from 'worker-communication';
import * as cluster from 'cluster';
// or       childProcess from 'child_process'

const cpc = new CPC();

const worker = cpc.tunnel(cluster.fork())
// or          cpc.tunnel(childProcess.fork('./worker.js'));

cpc.onWorker('requestJob', (req, res) => {
    res({
        reqHeader: req,
        timestamp: Date.now()
    }, null);
});

worker.sendJob('idle', 'just relax...');

Worker (cluster worker or child_process.fork())

import CPC from 'worker-communication';

const cpc = new CPC(); 

cpc.onMaster('idle', (req) => {
    console.log(req);
    // output: just relax...
});

let reqHeader = [123, 456];

cpc.sendJob('requestJob', reqHeader, (jobHeader, job) => {
    console.log(jobHeader);
    // output: { reqHeader: [123, 456], timestamp: 1577252484830 }
    console.log(job);
    // output: null
});

Note

Master & worker is relative, a worker can also be a master to the process it forks. So in this scenario, onMater() and onWorker() can be used at the same time to communicate its master and worker.

Keywords

worker

FAQs

Package last updated on 22 Jan 2020

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