All Projects → sibnerian → Electron Promise Ipc

sibnerian / Electron Promise Ipc

Licence: mit
Promise-flavored IPC calls in Electron. 100% test coverage.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Electron Promise Ipc

Scalecube Services
v2.0 - ScaleCube Services provides a low latency Reactive Microservices library for serverless service registry and discovery based on gossip protocol and without single point-of-failure or bottlenecks.
Stars: ✭ 23 (-58.18%)
Mutual labels:  ipc
Promise.hpp
C++ asynchronous promises like a Promises/A+
Stars: ✭ 31 (-43.64%)
Mutual labels:  promises
Caf
Cancelable Async Flows (CAF)
Stars: ✭ 1,027 (+1767.27%)
Mutual labels:  promises
Ipcservicemanager
Android进程间通信框架
Stars: ✭ 24 (-56.36%)
Mutual labels:  ipc
Ecommerce
A powerful and lightweight eCommerce platform using ReactJs, Graphql, PHP, and Mysql.
Stars: ✭ 28 (-49.09%)
Mutual labels:  promises
Dynogels Promisified
Promisifies methods exposed by dynogels (Dynamo DB mapper)
Stars: ✭ 36 (-34.55%)
Mutual labels:  promises
Minapp
重新定义微信小程序的开发
Stars: ✭ 902 (+1540%)
Mutual labels:  promises
Microservices Using Rabbitmq
Python & Go microservices on Docker, using RabbitMQ for asynchronous IPC
Stars: ✭ 51 (-7.27%)
Mutual labels:  ipc
Modern Async
A modern JavaScript tooling library for asynchronous operations using async/await and promises
Stars: ✭ 31 (-43.64%)
Mutual labels:  promises
Veza
IPC/TCP Networking Utility to connect several processes with great concurrency.
Stars: ✭ 45 (-18.18%)
Mutual labels:  ipc
Broadcast Channel
📡 BroadcastChannel to send data between different browser-tabs or nodejs-processes 📡
Stars: ✭ 843 (+1432.73%)
Mutual labels:  ipc
Asynchronous
Implementation-agnostic asynchronous code
Stars: ✭ 13 (-76.36%)
Mutual labels:  promises
Breeze
Javascript async flow control manager
Stars: ✭ 38 (-30.91%)
Mutual labels:  promises
Easymessenger
一款Android平台上基于Binder的IPC进程间通信库
Stars: ✭ 24 (-56.36%)
Mutual labels:  ipc
Node.pas
Asynchronous Event-driven server programming for EMB Delphi, powered by libuv.
Stars: ✭ 45 (-18.18%)
Mutual labels:  promises
Rpc Thunderdome
A comparison between Proteus RPC and other commonly used RPC frameworks
Stars: ✭ 22 (-60%)
Mutual labels:  ipc
Bluebird Api
Bluebird compatible API on top of native promises.
Stars: ✭ 36 (-34.55%)
Mutual labels:  promises
Redux Electron Ipc
Redux Electron IPC Middleware
Stars: ✭ 54 (-1.82%)
Mutual labels:  ipc
Qt Promise
Chainable promises for Qt
Stars: ✭ 48 (-12.73%)
Mutual labels:  promises
Easyfutures
Easy Swift Futures & Promises.
Stars: ✭ 40 (-27.27%)
Mutual labels:  promises

electron-promise-ipc

Build Status Coverage Status npm version

Promise-y IPC calls in Electron.

Installation

npm install --save electron-promise-ipc

Usage

The most common use case: from the renderer, get data from the main process as a promise.

// in main process
import promiseIpc from 'electron-promise-ipc';
import fsp from 'fs-promise';

promiseIpc.on('writeSettingsFile', (newSettings, event) => {
  return fsp.writeFile('~/.settings', newSettings);
});

// in renderer
import promiseIpc from 'electron-promise-ipc';

promiseIpc
  .send('writeSettingsFile', '{ "name": "Jeff" }')
  .then(() => console.log('You wrote the settings!'))
  .catch((e) => console.error(e));

You can also send data from the main process to a renderer, if you pass in its WebContents object.

// in main process
import promiseIpc from 'electron-promise-ipc';

promiseIpc
  .send('getRendererData', webContentsForRenderer)
  .then((rendererData) => console.log(rendererData))
  .catch((e) => console.error(e));

// in renderer
import promiseIpc from 'electron-promise-ipc';

promiseIpc.on('getRendererData', (event) => {
  return getSomeSuperAwesomeRendererData();
});

Any arguments to send() will be passed directly to the event listener from on(), followed by the IPC event object. If there is an error thrown in the main process's listener, or if the listener returns a rejected promise (e.g., lack of permissions for a file read), then the send() promise is rejected with the same error.

Note that because this is IPC, only JSON-serializable values can be passed as arguments or data. Classes and functions will generally not survive a round of serialization/deserialization.

Preload

As of Electron 5.0, nodeIntegration is disabled by default. This means that you cannot import promiseIpc directly. Instead, you will need to use a preload script when opening a BrowserWindow. Preload scripts can access builtins such as require even if nodeIntegration is disabled.

For convenience, this library provides a preload script which you can require that sets window.promiseIpc.

// preload.js
require('electron-promise-ipc/preload');

Advanced usage

Timeouts

By default, the promise will wait forever for the other process to return it some data. If you want to set a timeout (after which the promise will be rejected automatically), you can create another instance of PromiseIpc like so:

// main process code remains the same
import promiseIpc from 'electron-promise-ipc';

promiseIpc.on('someRoute', () => {
  return someOperationThatNeverCompletesUhOh();
});

// in renderer - timeout is specified on the side that requests the data
import { PromiseIpc } from 'electron-promise-ipc';

const promiseIpc = new PromiseIpc({ maxTimeoutMs: 2000 });

promiseIpc
  .send('someRoute', '{ "name": "Jeff" }')
  .then(() => console.log('You wrote the settings!'))
  .catch((e) => console.error(e)); // will error out after 2 seconds

Removing Listeners

You can remove a listener with the off() method. It's aliased to removeListener() as well.

import promiseIpc from 'electron-promise-ipc';

promiseIpc.on('someRoute', () => {
  return something();
});

promiseIpc.off('someRoute'); // never mind

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].