Skip to content

Instantly share code, notes, and snippets.

@justsml
Forked from joepie91/.js
Last active December 2, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justsml/939cf1b2b668e69a13e29ef997ea6ddb to your computer and use it in GitHub Desktop.
Save justsml/939cf1b2b668e69a13e29ef997ea6ddb to your computer and use it in GitHub Desktop.
Promise map (Bluebird)
const Bluebird = require('bluebird')
const got = require('got')
const urls = [
"http://www.google.com/",
"http://www.yahoo.com/",
"http://www.bing.com/",
];
// Bluebird is an extension of promises:
Bluebird.resolve(urls)
.map(url => got(url), {concurrency: 4})
.map(response => response.body)
.map((html, i) => {
// Now you can access/parse each response as `html` here, and reshape the value for the next `.then` or `.map`
return {html: html, url: urls[i]}
}, {concurrency: 8})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment