Skip to content

Instantly share code, notes, and snippets.

@vernak2539
Created March 11, 2018 15:16
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 vernak2539/d46d4c51134ae7d7f47db2507b2e01b9 to your computer and use it in GitHub Desktop.
Save vernak2539/d46d4c51134ae7d7f47db2507b2e01b9 to your computer and use it in GitHub Desktop.
const got = require('got');
const { parallelLimit } = require('async');
const body = { feature: 'my_feature', other: 'yes' };
const bodies = [
{ feature: 'my_feature', other: 'yes' },
{ feature: 'my_feature3', other: 'yes' },
{ feature: 'my_feature2', other: 'yes2' }
];
const queue = bodies.map(body => {
return cb => {
got
.post('http://localhost:3000/test', {
json: true,
body
})
.then(res => cb(null, { feature: body.feature, err: null, res: res.body || 'success' }))
.catch(err => {
cb(null, { feature: body.feature, err: err.response.body.error });
});
};
});
parallelLimit(queue, 50, (err, results) => {
console.log(JSON.stringify(err, null, 2));
console.log(JSON.stringify(results, null, 2));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment