1.0.0 • Published 8 years ago
mipc v1.0.0
mipc
Multiplexed IPC mipc provides a thin layer on top of the default ipc with an EventEmitter like api.
Installation
npm i mipcUsage
const mipc = require('mipc')
const channel = mipc(target)- target
<Process>- The target process. This can be any object that is anEventEmitterand has asend(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,optionsandcallbackarguments 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!
1.0.0
8 years ago