Electron Js 中 MessagePorts 的实际用法是什么?

What is the practical usages of MessagePorts in electron Js?

Electron Js中MessagePorts的实际用法是什么?为什么我们需要这个?相反,我们不能使用 ipcRenderer.invoke 吗?我看不到 MessagePorts 的任何实际用法。它只是主进程和渲染进程之间的数据传输,如 ipcRenderer.invoke 和 ipcMain.handle。 能不能告诉我一个只能用MessagePort解决而用ipcRenderer.invoke和ipcMain.handle解决不了的实际问题?

回答我自己。 基本上在官方文档中,他们给出了 Channel Messaging 的三种用法示例 API.

我们可以阅读那些例子来理解。 (第一次没看到所以糊涂了)

  1. Worker process
  2. Reply streams
  3. Communicating directly between the main process and the main world of a context-isolated page