Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toyobayashi/electron-function-ipc
Make ipcRenderer/ipcMain support passing function as parameter.
https://github.com/toyobayashi/electron-function-ipc
Last synced: 10 days ago
JSON representation
Make ipcRenderer/ipcMain support passing function as parameter.
- Host: GitHub
- URL: https://github.com/toyobayashi/electron-function-ipc
- Owner: toyobayashi
- License: mit
- Created: 2018-12-16T05:41:48.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-07T04:25:40.000Z (over 4 years ago)
- Last Synced: 2024-11-05T22:47:22.693Z (about 2 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# electron-function-ipc
## Usage
```js
// main process
const ipcMain = require('electron-function-ipc/main.js')ipcMain.on('123', async function (e, rendererCallback) {
console.log(rendererCallback.toString())
console.log(rendererCallback.name)
const returnFunction = await rendererCallback(function mainCallback(s) {
console.log(s)
throw new TypeError(s)
// return s
}) // return Promise
console.log(returnFunction.toString())
console.log(returnFunction.name)
const obj = await new returnFunction('888')
console.log(obj.m)
})
``````js
// renderer process
const ipcRenderer = require('electron-function-ipc/renderer.js')ipcRenderer.send('123', async function rendererCallback(mainCallback) {
console.log(mainCallback.toString())
console.log(mainCallback.name)
try {
const s = await mainCallback('666') // return Promise
console.log(s)
} catch (err) {
console.log(err)
}return function returnFunction(a) {
this.m = a
}
})
```## Note
* Function invoked in another process returns promise even if it is not an async function, so you can use async/await syntax.
* Passing es5/es6 class is also ok but method is not supported.
* Function `this` can not be changed by `call()` / `apply()` / `bind()`.