Needlessly Provoking Marsupials

npm

Don't miss out on this year's npm Pride t-shirt designs!Order your favorites here »

childprocess-messageport

1.0.0 • Public • Published

childprocess-messageport

npm version Build Status

Turns ChildProcess IPC into MessagePort.

Background

Instead of learning/using different API for different communication channels, we should unite them into a single interface pattern, either MessagePort or WebSocket.

How to use

const childProcess = ChildProcess.fork('echo.js');
const messagePort = new ChildProcessMessagePort(childProcess);
 
messagePort.onmessage = event => {
  // Could be either a string or Buffer
  console.log(event.data);
};
 
messagePort.postMessage('Hello, World!');

Instead of subscribing to onmessage, you can also subscribe using on('message', handler).

If the underlying childProcess.send is failed, an error event will be emitted.

Contributions

Like us? Star us.

Want to make it better? File us an issue.

Don't like something you see? Submit a pull request.

install

npm i childprocess-messageport

Downloadsweekly downloads

6

version

1.0.0

license

MIT

last publish

collaborators

  • avatar
Report a vulnerability