title: Get returned values with promise.all() and an async map function
body: <p>Sorry if the question doesn't make a lot of sense, because it's honestly going to be hard for me to explain, but the gist of it is that I have a list of images that I need to get from our <code>AWS S3</code> bucket inside an async map function.  After it has iterated through all of the images that I need, I need to return the results outside of the <code>Promise.all()</code> method that this map function is inside.  Let me show you what I meant by the code I have.</p>
  <pre><code>let res = Promise.all(ads.map(async (ad) =&gt; {
              let result = await ListObjects('bucket', '/', `Items/${ad.ID}_${ad.Year}`, (response) =&gt; {
                  if(!response){
                      console.error('There was an issue getting these images');
                  }else if(response.Contents.length &gt; 0){
                      let list = response.Contents.map(obj =&gt; ({Path: obj.Key, Date: new Date(obj.LastModified).getTime()}));
                      list.sort((a,b) =&gt; a.Date &lt; b.Date ? 11 : a.Date &gt; b.Date ? -1 : 0);
                      return list[0];
                  }else{
                      console.log('no previous ads')
                  }
              })
  
              console.log(result);  // I expect a single object from ListObjects but I get undefined
  
              return result
          }));
  
          console.log(res); // expecting to get an array of objects here, but I get undefined
          return res;
  }
  </code></pre>
  <pre><code>export const ListObjects = (bucket, delimeter, prefix, callback) =&gt; {
      try{
          // could just use the s3 client config instead.
          aws.config.update({
              accessKeyId: access_key,
              secretAccessKey: secret_access_key,
              region: 'myregion'
          });
      
          const s3 = new S3();
          s3.listObjectsV2({
              Bucket: bucket,
              Delimiter: delimeter,
              Prefix: prefix
          }, (err,data) =&gt; {
              if(err){
                  console.error(err);
                  callback(false);
              }else{
                  callback(data);
              }
          })
      }catch(e){
          console.log('ERROR: S3.ListObjects: ' + e);
          callback(false);
      }
  }
  
  </code></pre>
  <p>My <code>ListObjects</code> method uses a callback and I'm not sure if this would need to be a promise instead of a callback function to make this request possible, but any clue on how I can make this possible would really help.  TIA!</p>