Send IPC call and wait for promise



Is there a way that when an IPC call is made from the renderer to the main process, that it waits for the main process to return its promise ?

I would like to make an api in my main process and it would be ideal if I wouldn’t have to add a listener for every request i make in the renderer.

Much like in angular :

    function asyncGreet(name) {
        var deferred = $q.defer();
        setTimeout(function() {
            deferred.notify('About to greet ' + name + '.');
            if (okToGreet(name)) {
                deferred.resolve('Hello, ' + name + '!');
            } else {
                deferred.reject('Greeting ' + name + ' is not allowed.');
        }, 1000);
        return deferred.promise;
    var promise = asyncGreet('Robin Hood');
    promise.then(function(greeting) {
        alert('Success: ' + greeting);
    }, function(reason) {
        alert('Failed: ' + reason);
    }, function(update) {
        alert('Got notification: ' + update);

Correct handle Promise returned from ipc

Take a look at:

Also note:

When you invoke methods of a remote object, call a remote function, …, you are actually sending synchronous inter-process messages


hello, thanks for the response.

After working with electron a little bit i quickly noticed that 99% of my logic should be based in the renderer and to keep the main to a minimum. So i won’t be using any promises from the main to the renderer.

The above examples are more event listeners, or am I mistaken ?