Last active
August 22, 2017 07:45
-
-
Save freeart/936307021b78929ab2e3a716c3bb7c00 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 request = require('request'); | |
const async = require('async'); | |
function send(data, cb) { | |
request(data, (err, res, body) => { | |
if (!err && (res.statusCode > 0 && res.statusCode < 400)) { | |
return cb && cb(null, body) | |
} | |
if (!err && (res.statusCode >= 400 || res.statusCode <= 0)) { | |
console.error(res.statusCode) | |
return cb && cb("status " + res.statusCode) | |
} | |
if (err) { | |
console.error(err.toString()) | |
} | |
cb && cb(err); | |
}); | |
} | |
//wrong way to call async code | |
for (let i = 0; i < 1000; i++) { | |
send({ | |
uri: "http://jsonplaceholder.typicode.com/posts", | |
method: 'POST', | |
json: true, | |
followAllRedirects: true, | |
body: { | |
title: 'foo', | |
body: 'bar', | |
userId: 1 | |
}, | |
timeout: 5000 | |
}) | |
} | |
console.log("fake done") | |
//simulate infinity loop | |
setTimeout(function fake(){ | |
setTimeout(fake, 1000); | |
}, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment