Parallelizing requests in JavaScript

Here are a couple of modern ways to parallize requests. Disclaimer, this code has not been executed.

Using Promise.all (Bluebird)

const Promise = require('bluebird');

const getResponses = async (urls) => {
  const requests = urls.map(u => fetch /* fetch is a newish builtin API */)
  const responses = await Promise.all(requests)
  return responses
}

const urls = [
  'https://foo.com/bar.json',
  'https://foo.com/baz.json',
  'https://foo.com/qux.json'
]

(async () => {
  const responses = getResponses(urls)
})()

Using async/await & for-of

const getResponses = async (urls) => {
  const requests = urls.map(u => fetch /* fetch is a newish builtin API */)
  const responses = []

  for (let url of urls) {
    const response = await fetch(url)
    responses.push(response)
  }

  return responses
}

const urls = [
  'https://foo.com/bar.json',
  'https://foo.com/baz.json',
  'https://foo.com/qux.json'
]

(async () => {
  const responses = getResponses(urls)
})()