title: Waiting for multiple ipc calls to complete before continuing in electron/redux
body: <p>I'm working on an app in Electron, React and Redux. At the program start, I'm making a few asynchronous ipc calls between the render process and the main process and save the results in the store.</p>
  
  <pre><code>// in the main app component
  componentWillMount() {
      const { store } = this.context;
      store.dispatch(fetchOptions());
      store.dispatch(fetchRequirements());
      store.dispatch(fetchStats());
      /* miracle function */
  },
  
  // actions.js
  export function fetchOptions() {
      return dispatch =&gt; {
          dispatch(requestOptions());
          ipcRenderer.on('sendOptions', function(event, arg) {
              dispatch(receiveOptions(arg));
          });
          ipcRenderer.send('requestOptions', '');
      };
  }
  // others accordingly
  </code></pre>
  
  <p><code>receiveOptions(arg)</code>, <code>receiveRequirements(arg)</code> and <code>receiveStats(arg)</code> are action creators and finally the reducer will save the responses in the store. </p>
  
  <p>Directly after <code>store.dispatch(fetchStats())</code>, I want to dispatch another action to make some calculations based on the values that were loaded into the store. However, this action will usually be dispatched before the responses from ipc arrive. </p>
  
  <p>I found <a href="https://github.com/reactjs/redux/issues/723" rel="nofollow">this discussion</a> with a similar problem, but they are making api calls with <code>fetch</code> instead of ipc messages, and I wouldn't know how to apply their idea to my problem.</p>
  
  <p>So here is my question: how can I make the program wait for responses from all the channels before continuing?</p>
  
  <p>Edit: When I set a time out of length 0 for the dispatches after the ipc calls, it works at least with immediate responses, but of course it doesn't help when the responses take a bit longer.</p>
  
  <pre><code>store.dispatch(fetchOptions());
  store.dispatch(fetchRequirements());
  store.dispatch(fetchStats());
  
  setTimeout(function() {
      store.dispatch(calculateThis());
      store.dispatch(calculateThat());
  }, 0);
  </code></pre>