title: Wait for array.map iterations in Promise.all
body: <p>I have the following code that should add items for customers if they dont already exist. Execution should be in parallel.</p>
  <pre><code>await Promise.all(
      customers.map(async (customer) =&gt; {
          return customer.items.map(async (item) =&gt; {
              return new Promise(async (resolve) =&gt; {
                  const productExists = someArray.some(
                      (arrayValue) =&gt; arrayValue === item.id
                  );
                  if (!productExists) {
                      logger.info(
                      `customer item ${item.id} does not exist, creating...`
                      );
                      await createCustomerItem(item.id);
                      logger.info(`customer item ${item.id} created.`);
  
                      someArray.push(item.id);
                  } else {
                      logger.info(`customer item ${item.id} already exists, skipping...`);
                  }
                  resolve(true);
              });
          });
      })
  
  );
  
  logger.info(`All items should now be present`);
  </code></pre>
  <p>The problem is that the execution is not waiting for <code>createCustomerItem</code> to resolve in the cases of <code>!productExists)</code></p>
  <p>This is the log</p>
  <pre><code>customer item 32310 does not exist, creating...
  customer item ao does not exist, creating...
  customer item ute does not exist, creating...
  All items should not be present
  customer item ao created.
  customer item ute created.
  customer item 32310 created.
  </code></pre>
  <p>Naturally <code>All items should not be present</code> should come last.</p>
  <p>When all the items already exist, then the process looks good.</p>