Skip to content

Instantly share code, notes, and snippets.

@mchelen
Last active September 19, 2017 00:38
Show Gist options
  • Save mchelen/16463df393bf3be7aa896f6909644400 to your computer and use it in GitHub Desktop.
Save mchelen/16463df393bf3be7aa896f6909644400 to your computer and use it in GitHub Desktop.
Node async parallel example
node_modules
var request = require('request');
var async = require('async');
async.parallel(
[
function(callback) {
request('https://jsonplaceholder.typicode.com/posts/1', function (error, response, body) {
var data = JSON.parse(body);
callback(null, data);
});
},
function(callback) {
request('https://jsonplaceholder.typicode.com/posts/2', function (error, response, body) {
var data = JSON.parse(body);
callback(null, data);
});
}
],
function(err, results) {
results.forEach(function(element) {
console.log("title: ", element.title);
});
}
);
{
"name": "node-async",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^2.5.0",
"request": "^2.81.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment