Skip to content

Commit 1a792af

Browse files
committed
fixing async call program
1 parent 5f845ef commit 1a792af

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
http = require("http");
1+
var http = require("http");
22

3-
tiempo_inicial = new Date();
3+
var req = http.get("http://en.wikipedia.org/wiki/España", function(res) {
4+
var pageData = "";
5+
res.on('data', function(chunk) {
6+
pageData += chunk;
7+
});
48

5-
palabros = [ "arbol", "boca", "casa", "dedo", "eco", "fuego", "ganso" ]
9+
res.on("error", function() {
10+
console.log("error")
11+
});
612

7-
total_respuestas = palabros.length;
8-
9-
palabros.forEach(function(value, index) {
10-
console.log(value, "INICIO");
11-
http.get({
12-
host : "es.wikipedia.org",
13-
path : "/wiki/" + value
14-
}, function(res) {
15-
res.on('end', function() {
16-
console.log(value, "FIN");
17-
total_respuestas--;
18-
if (total_respuestas == 0) {
19-
tiempo_final = new Date();
20-
console.log("Tiempo total:", tiempo_final.getTime() - tiempo_inicial.getTime());
21-
}
22-
});
23-
});
24-
});
13+
res.on('end', function() {
14+
console.log(pageData);
15+
console.log("end");
16+
});
17+
});

0 commit comments

Comments
 (0)