包详细信息

sendmessage

node-modules140.9kMIT3.0.1

Send a cross process message if message channel is connected.

sendmessage, send, cluster, message

自述文件

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.

更新日志

Changelog

3.0.1 (2024-12-11)

Bug Fixes

3.0.0 (2024-06-23)

⚠ BREAKING CHANGES

  • drop Node.js < 18.19.0 support

part of https://github.com/eggjs/egg/issues/3644

https://github.com/eggjs/egg/issues/5257

Features

  • support cjs and esm both by tshy (#6) (30acc65)

2.0.0 (2023-06-13)

⚠ BREAKING CHANGES

  • Drop Node.js < 14 support

Features

  • support worker_threads ipc (#3) (3a27475)
  • use github action and drop non-lts Node.js support (#4) (9592a9b)

1.1.0 / 2016-11-02

  • feat: add more env SENDMESSAGE_ONE_PROCESS (#2)

1.0.5 / 2015-04-14

  • support IS_NODE_DEV_RUNNER env

1.0.4 / 2014-12-04

  • fix: try to detect node-dev env, dont use NODE_ENV

1.0.3 / 2014-11-21

  • use NODE_ENV === 'development'

1.0.2 / 2014-11-21

  • fix missing message on node-dev

1.0.1 / 2014-11-14

  • fix: support cluster.fork() child process

1.0.0 / 2014-11-14

  • first commit