-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why one works and other doesn't work to async juggling? #698
Comments
I personally find the for loop confusing. Perhaps this will provide you with some clarity: 'use-strict';
const http = require('http')
const url1 = process.argv[2];
const url2 = process.argv[3];
const url3 = process.argv[4];
// see notes
getContents(url1, function () {
getContents(url2, function () {
getContents(url3);
});
});
function getContents(url, callback) {
http.get(url, function (res) {
let rawData = "";
res.setEncoding('utf8');
res.on('error', function(err) {
return console.log(err)
})
res.on('data', function(data) {
rawData += data;
});
res.on('end', function() {
console.log(rawData);
callback ? callback() : null;
})
})
} Notes: Also the getContents example are known as a callback hell. For a later stage probably something such as async await would be more useful. But for this exercise we actually |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution works
Where as this one doesn't work
The only difference the method **getData(i) ** , why one works and other doesn't
any ideas ?
The text was updated successfully, but these errors were encountered: