title: javascript node.js async-await electron
body: <p>I can't seem to find a relevant solution to this issue.</p>
  
  <p>I am trying to use a foreach loop to call out for data. I have tried multiple variations of packaging this in promises but cannot seem to halt this function from proceeding before finishing the loop. Hoping someone may have some insight.</p>
  
  <pre><code>    async function getData(){
      temparray [] = { data to iterate over };
  
      await getAgents();
      console.log('done');
  
      function getAgents(){
      return new Promise(resolve =&gt; {
              temparray.forEach((deal) =&gt; { 
                   pipedrive.Persons.get(deal.agent, function(err, person) {
                      if (err) throw err;
                      console.log("trying to get agent " + deal.agent)
                      console.log(person.name);
                   });
              });
          }); // end of promise
      }; 
  };
  </code></pre>
  
  <p>So what I'm trying to do here is create a promise that resolves once all of the async calls are completed, but the process marches on before this has completed. Hence 'done' logs to the console before the getAgents() function has completed and logged the names. I suspect it has to do with the callbacks, but I've tried converting it to a promise, I've tried util.promiseify, and I've looked at building an array of promises and then using promise.all but haven't tested it.</p>