title: javascript promise handling
body: <p>I'm using <a href="https://www.npmjs.com/package/node-unifi" rel="nofollow noreferrer">node-unifi</a> and the basic structure looks structure of a request looks like:</p>
  <pre><code>const unifi = require('node-unifi');
  const controller = new unifi.Controller({host: '127.0.0.1', port: 8443, sslverify: false});
  
  controller.login('admin', 'PASSWORD')
    .then(result =&gt; {
      console.log('login: ' + result);
      return controller.createnetwork(payload);
    });
  </code></pre>
  <p>I'm trying to wrap the 'controller.createnetwork(payload)' call into a for loop. If I use a return statement, it dutifully breaks out of the loop upon the first run. If I remove the return, I get an UnhandledPromiseRejectionWarning and only the last iteration of the loop actually gets submitted.</p>
  <p>What's the proper method for calling a function like this in a loop while fulfilling the Promise?</p>
  <p>Thanks in advance.</p>