#IPC one channel vs multiple channels

1 messages · Page 1 of 1 (latest)

ember marsh
#

I have been wondering for a while now what is the best approach when it comes to IPC across main and multiple renderers:
a) a few IPC channel with type+payload style messages with thin routing layer
b) many IPC channels with one payload type per channel

The documentation has no information on how expensive creating IPC channels is, that would help me guide my decision.

Any recommendations or experience to share?

grim raft
#

Personally, I use APIs like:

const ipcApi = {
  call: {
    worker: (channel, ...args) => {
      const allowedChannels = [...];

      if (!allowedChannels.includes(channel)) return sendError(...);
      sendToWorker(channel, ...args);
    },
    main: (channel, ...args) => {
      const allowedChannels = [...];

      if (!allowedChannels.includes(channel)) return sendError(...);
      sendToMain(channel, ...args);
    }
  },
  ...
};

worker is another renderer, I use main to pass messages between renderers because I don't like the MessagePorts API (but it's less performant like this).