0.0.3 • Published 4 years ago

electron-ipc-promises v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

electron-ipc-promises (0.0.3)

Electron's IPC with Promises:

Main Process:

import ipc from "electron-ipc-promises"

ipc.main.on("add-sync", num => {
	return num + 1
})

ipc.main.on("add-async", num => {
	return new Promise(resolve => {
		setTimeout(() => {
			resolve(num + 1)
		}, 2000)
	})
})

Renderer Process:

import ipc from "electron-ipc-promises"

ipc.renderer.send("add-sync", 3)
.then(result => {
	console.log(result) // 4
})

ipc.renderer.send("add-async", 3)
.then(result => {
	console.log(result) // 4 after 2 seconds
})

Same thing goes the other way around too (from main to renderer).

Installation

$ npm install --save electron-ipc-promises

or ...

$ yarn add electron-ipc-promises

Testing

Run $ npm run test.