feat: add ipcRenderer.invoke() (#18449)
This commit is contained in:
parent
b180fb376c
commit
c436997840
17 changed files with 389 additions and 20 deletions
|
@ -57,10 +57,39 @@ Removes all listeners, or those of the specified `channel`.
|
|||
* `...args` any[]
|
||||
|
||||
Send a message to the main process asynchronously via `channel`, you can also
|
||||
send arbitrary arguments. Arguments will be serialized in JSON internally and
|
||||
send arbitrary arguments. Arguments will be serialized as JSON internally and
|
||||
hence no functions or prototype chain will be included.
|
||||
|
||||
The main process handles it by listening for `channel` with [`ipcMain`](ipc-main.md) module.
|
||||
The main process handles it by listening for `channel` with the
|
||||
[`ipcMain`](ipc-main.md) module.
|
||||
|
||||
### `ipcRenderer.invoke(channel[, arg1][, arg2][, ...])`
|
||||
|
||||
* `channel` String
|
||||
* `...args` any[]
|
||||
|
||||
Returns `Promise<any>` - Resolves with the response from the main process.
|
||||
|
||||
Send a message to the main process asynchronously via `channel` and expect an
|
||||
asynchronous result. Arguments will be serialized as JSON internally and
|
||||
hence no functions or prototype chain will be included.
|
||||
|
||||
The main process should listen for `channel` with
|
||||
[`ipcMain.handle()`](ipc-main.md#ipcmainhandlechannel-listener).
|
||||
|
||||
For example:
|
||||
```javascript
|
||||
// Renderer process
|
||||
ipcRenderer.invoke('some-name', someArgument).then((result) => {
|
||||
// ...
|
||||
})
|
||||
|
||||
// Main process
|
||||
ipcMain.handle('some-name', async (event, someArgument) => {
|
||||
const result = await doSomeWork(someArgument)
|
||||
return result
|
||||
})
|
||||
```
|
||||
|
||||
### `ipcRenderer.sendSync(channel[, arg1][, arg2][, ...])`
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue