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 = const channel =
- target
<Process>
- The target process. This can be any object that is anEventEmitter
and has asend(msg)
function. - channel
<mipc.Channel>
- The communication channel for the target process.
Sending Messages
channel channelchannel
- eventHame
<string>
The event name. - value
<any>
- The event value. - options - The
sendHandle
,options
andcallback
arguments that are passed to process.send.
Listening For Messages
channel is an EventEmitter
. For each inbound message, an event will be emitted.
channel channel
When using the sendHandle
option, the handle is passed with the second argument.
Waiting For Messages
const value sendHandle = await channel const magic = await channelconsole // -> 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!