【问题标题】:Is there any way to abort an ipc async request sending in electron?有没有办法中止在电子中发送的 ipc 异步请求?
【发布时间】:2016-10-25 04:48:50
【问题描述】:

我编写了一些代码用于通过电子中的 ipc 发送异步请求,但我想知道如何中止或取消我已经发出的 ipc 请求。

ipc.on('receivedSoftwareInfo', (info) => {
    // TO-DO
});

ipc.send('getSoftwareInfo');

我从 electron 的Repo 搜索了 api 文档,得到了一条信息,我可以通过调用 removeListener 来停止,如下代码所示,这样我绑定的事件就不会触发。

ipc.removeAllListeners();

但我认为如果用户单击按钮并立即再次请求,则会出现潜在问题,它会在程序端删除所有侦听器,然后 ipc 第二次发送请求。

它看起来像以下流程:

Events are removed -> async request is still there -> bind events again -> trigger
(I don't want it happen and trigger by old request)

那么,有什么方法可以中止在电子中发送的 ipc 异步请求?我认为解决这个问题比删除所有听众要好。

【问题讨论】:

    标签: asynchronous ecmascript-6 listener ipc electron


    【解决方案1】:

    不幸的是,这是不可能的。 IPC 请求由浏览器(此处为 Electron)管理,无法在 JavaScript 中管理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-20
      • 2018-09-25
      • 1970-01-01
      • 2013-01-16
      • 2019-02-20
      • 2013-10-19
      • 2021-06-12
      • 2017-03-24
      相关资源
      最近更新 更多