Skip to content
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 won't my solution to async juggling work? #491

Open
dhaliman opened this issue Nov 21, 2016 · 1 comment
Open

Why won't my solution to async juggling work? #491

dhaliman opened this issue Nov 21, 2016 · 1 comment

Comments

@dhaliman
Copy link

dhaliman commented Nov 21, 2016

Here is what I've written for Async Juggling. Could anyone explain why it doesn't work?
`var http = require('http');
const url1 = process.argv[2];
const url2 = process.argv[3];
const url3 = process.argv[4];

function GetData ( url, callback ) {
http.get(process.argv[2], function (response) {
var str = '';
response.on('data', function(data) {
str += data.toString();
})
response.on('end', function() {
callback(str);
})
});
}

GetData (url1, function(err, data) {
if (err) {
console.log(err);
}
else {
console.log(data);
GetData (url2, function(err, data) {
if (err) {
console.log(err);
}
else {
console.log(data);
GetData (url3, function(err, data) {
if (err) {
console.log(err);
}
else {
console.log(data);
}
});
}
});
}
});`

Thanks
Manmeet

@Chrinkus
Copy link
Contributor

You're setting specific variables to the three urls that you're given but every GetData call uses only the first url (process.argv[2]).

Try http.get(url, function(response) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants