Created
March 11, 2018 15:16
-
-
Save vernak2539/d46d4c51134ae7d7f47db2507b2e01b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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