title: waiting with code execution for input
body: <p>In an Electron application I need to alter an array of objects, I receive from an Excel File.</p>
  
  <p>As long as there is no user Input in this functions this works great, but there is an option for the user to link a directory with filenames into that array. </p>
  
  <p>If I open a dialog to choose the directory I'd need my script to stop and wait for the user input but can't see how to do that. Simplified my code looks like:</p>
  
  <pre><code>let initialArray = [];
  
  let Arr1=[];
  let Arr2=[];
  let arrayFiles=[];
  
  let outputData = [];
  
  document.getElementById('importExcel').addEventListener('change', handleFile, false);
  
  function handleFile(e) {
      //get initial Array an fill it with Data
      let q = new Promise(function (resolve, reject) {
          for (let x of initialArray) {
              //extract Data for Arr1 and push it there
              //extract Data for Arr2 and push it there
          }
          resolve();
      }
      q.then(workOnArr1).then(getFiles).then(workOnArr1and2).then(mergeData).catch(console.log.bind(console));
  }
  function workOnArr1() {
      //rearranging and adding Data to Arr1
  }
  function getFiles() {
      if (document.getElementById("getFileData").checked) {
          dialog.showOpenDialog({properties: ['openDirectory']}, function (filePaths) {
              //here it should stop until a directory is chosen and the filenames
              // are read into arrayFiles
              fs.readdirSync(filePaths[0]).forEach(file =&gt; {
                  arrayFiles.push(file)
              });
          });
      }
  }
  function workOnArr1and2() {
      //alter Arr1 and integrate the Data of arrayFiles into it
      for (let x of Arr1) {
          //that does not work, because the script does not stop at the dialog,
          //arrayFiles is always empty when this line is executed
          for (let y of arrayFiles) 
              if (somecondition) {
                  x.subArray = y
              }
      }
      //alter and reshape Arr2
  }
  function mergeData() {
      outputData = _.concat(Arr1,Arr2);
      //write outputData to DB
  } 
  </code></pre>
  
  <p>As I understood chaining functions with <code>then</code>after a <code>Promise</code> waits for one function to finish before the next one is executed. But as it seems I missed some crucial points or may be completely wrong with my assumption.</p>