Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.