Source code of released version | Source code of development version
Support for sending messages between a parent process and a child process that was spawned (by the parent) with an IPC channel.
After spawning a child process, calling
childProcess.sendMessage(topic, payload), which delivers
any listeners in the child process that were registered for the given
Child processes register themselves to receive messages by calling
onMessage(topic, callback). The
callback function may return a
Promise, in which case the parent will receive an array of callback
results from all children that subscribed to the given
topic, after the
results have been resolved.
Note that both
payload and the response values from the child process
listeners will be serialized for delivery between processes, though the
serialization library used by this
code is more robust than JSON, so it can handle circular and repeated
Maps that contain themselves, etc.
The key features that differentiate this API from the native Node
APIs are (1) restricting messages to a particular topic string, (2) more
robust serialization logic thanks to
arson, and (3) reliable responses
from all listener callbacks in the child process, which lets the parent
process proceed with confidence that the child is done with its work.