Skip to main content

类:IpcMainServiceWorker

类:IpcMainServiceWorker

🌐 Class: IpcMainServiceWorker

从主进程异步与服务工作线程通信。

进程:主进程

🌐 Process: Main

note

这个 API 是 IpcMain 的一个微妙变体——专门用于与服务工作线程通信。要与网页框架通信,请查阅 IpcMain 文档。

warning

Electron 内置的类不能在用户代码中被继承。 欲了解更多信息,请参见 常见问题

实例方法

🌐 Instance Methods

ipcMainServiceWorker.on(channel, listener)

监听 channel,当有新消息到达时,listener 会被调用,并传入 listener(event, args...)

🌐 Listens to channel, when a new message arrives listener would be called with listener(event, args...).

ipcMainServiceWorker.once(channel, listener)

为该事件添加一次性的 listener 函数。这个 listener 只会在下一次向 channel 发送消息时被调用,之后它将被移除。

🌐 Adds a one time listener function for the event. This listener is invoked only the next time a message is sent to channel, after which it is removed.

ipcMainServiceWorker.removeListener(channel, listener)

  • channel 字符串
  • listener 函数
    • ...args any[]

从指定的 channel 的监听器数组中移除指定的 listener

🌐 Removes the specified listener from the listener array for the specified channel.

ipcMainServiceWorker.removeAllListeners([channel])

  • channel 字符串(可选)

移除指定 channel 的监听器。

🌐 Removes listeners of the specified channel.

ipcMainServiceWorker.handle(channel, listener)

ipcMainServiceWorker.handleOnce(channel, listener)

处理单个 invoke 可用的 IPC 消息,然后移除监听器。参见 ipcMainServiceWorker.handle(channel, listener)

🌐 Handles a single invokeable IPC message, then removes the listener. See ipcMainServiceWorker.handle(channel, listener).

ipcMainServiceWorker.removeHandler(channel)

  • channel 字符串

如果存在,移除 channel 的任何处理程序。

🌐 Removes any handler for channel, if present.