sendmessage
Send a cross process message if message channel is connected.
Last updated 2 years ago by fengmk2 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install sendmessage 
SYNC missed versions from official npm registry.

sendmessage

NPM version CI Test coverage npm download

Send a cross process message if message channel is connected. Avoid channel closed error throw out.

Install

npm install sendmessage --save

Usage

master.js

import { fork } from 'node:child_process';
import { sendmessage } from 'sendmessage';

const worker = fork('./worker.js');

sendmessage(worker, { hi: 'this is a message to worker' });

worker.js

import { sendmessage } from 'sendmessage';

sendmessage(process, { hello: 'this is a message to master' });

API

#sendmessage(childProcess, message)

Send a cross process message. If a process is not child process, this will just call process.emit('message', message) instead.

  • childProcess: child process instance
  • message: the message need to send
sendmessage(process, { hello: 'this is a message to master' });

You can switch to process.emit('message', message) using process.env.SENDMESSAGE_ONE_PROCESS

License

MIT

Contributors

Contributors

Made with contributors-img.

Current Tags

  • 3.0.2                                ...           latest (a year ago)

11 Versions

  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.5                                ...           12 years ago
  • 1.0.4                                ...           12 years ago
  • 1.0.3                                ...           12 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 16
Today 0
This Week 2
This Month 2
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (12)
Dependents (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE