mipc

1.0.0 • Public • Published

mipc

Multiplexed IPC
mipc provides a thin layer on top of the default ipc with an EventEmitter like api.

Installation

npm i mipc

Usage

const mipc = require('mipc')
 
const channel = mipc(target)
  • target <Process> - The target process. This can be any object that is an EventEmitter and has a send(msg) function.
  • channel <mipc.Channel> - The communication channel for the target process.

Sending Messages

channel.send(eventName, value, ...options)
 
channel.send('foo', 42)
channel.send('foo', 42, () => {
    console.log('Message was sent!')
})
  • eventHame <string> The event name.
  • value <any> - The event value.
  • options - The sendHandle, options and callback arguments that are passed to process.send.

Listening For Messages

channel is an EventEmitter. For each inbound message, an event will be emitted.

channel.on(eventName, (value, sendHandle) => ...)
 
channel.on('foo', magic => {
    console.log(magic) // -> 42
})

When using the sendHandle option, the handle is passed with the second argument.

Waiting For Messages

const [value, sendHandle] = await channel.promise(eventName[, timeout])
 
const [magic] = await channel.promise('foo')
console.log(magic) // -> 42
  • eventName <string> - The event to await.
  • timeout <number> - If timeout is a number, the promise will reject after the timeout in milliseconds. Otherwise there is no timeout!

Readme

Keywords

none

Package Sidebar

Install

npm i mipc

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.73 kB

Total Files

7

Last publish

Collaborators

  • mpt