1.3.5 • Published 2 years ago

interprocess-communication v1.3.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Welcome to interpocess-communication documentation

ABOUT ME

Social networks

What's interprocess-communication?

Arousa interprocess-communication is a tool which helps you to send and recive messages between parent and child processes using promises.

Examples

Parent file

const {fork} = require("child_process");
const {Child} = require("interprocess-communication");

const child = new Child(fork("./child"));

child.send("Hello from parent!").then((message) => {
  console.log(message.payload);
});

child.on("message", (message) => {
  console.log(message.payload);
  if (message.payload === "Hello from child!")
    message.reply("Reply from parent!");
});

Child file

const {Parent} = require("interprocess-communication");

const parent = new Parent();

parent.send("Hello from child!").then((message) => {
  console.log(message.payload);
});

parent.on("message", (message) => {
  console.log(message.payload);
  if (message.payload === "Hello from parent!")
    message.reply("Reply from child!");
});

\(messageLifetime)

Parent constructor

Params

typeoptionaldescription
messageLifetimenumberTime until a messages is deleted from cache

\(childProcess, messageLifetime)

Parent constructor

Params

typeoptionaldescription
childProcessChildProcess ObjectReturned object from fork function
messageLifetimenumberTime until a messages is deleted from cache

<Child|Parent>.send(payload, replying, event)

Sends a message to the parent or the child

Params

typeoptionaldescription
payloadanyThe content to send in the message
replyingmessage id(number)Message id to reply
eventstringEvent name

.reply(payload, replying, event)

Replies the message

Params

typeoptionaldescription
payloadanyThe content to send in the message

Special events

There are 3 special events launched once a message is sent.

  • raw: Contains all messages json data. Its lauched every time a message is sent.
  • unhandledReply: Contains a reply that could not be resolved.
  • unhandledEvent: Contains a message that has no event (those messages are suposed to not appear).
1.3.5

2 years ago

1.3.4

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago