JUGGLING ASYNC (Exercise 9 of 13)
This problem is the same as the previous problem (HTTP COLLECT) in that you need to use http.get().
这个问题和前面的问题(HTTP COLLECT)是一样的,你需要使用http.get()。
However, this time you will be provided with three URLs as the first three command-line arguments.
然而,这次你将获得三个URL作为前三个命令行参数。
You must collect the complete content provided to you by each of the URLs and print it to the console (stdout).
您必须收集每个URL提供给您的完整内容并将其打印到控制台(stdout)。
You don't need to print out the length, just the data as a String; one line per URL.
你不需要打印出长度,只需将数据打印为字符串; 每个URL一行。
The catch is that you must print them out in the same order as the URLs are provided to you as command-line arguments.
问题在于,你必须按照提供给你的URL和命令行参数相同的顺序打印出来。
─────────────────────────────────────────────────────────────────────────────
HINTS
Don't expect these three servers to play nicely!
不要期望这三台服务器担任的很好!
They are not going to give you complete responses in the order you hope, so you can't naively just print the output as you get it because they will be out of order.
他们不会按照你希望的顺序给你完整的答复,所以你不能天真地打印输出你取得的东西,因为他们会发生故障。
You will need to queue the results and keep track of how many of the URLs have returned their entire contents.
您需要对结果进行排序然后跟踪有多少个网址已经返回了他们的全部内容。
Only once you have them all, you can print the data to the console.
只要你全部获得了他们,你就能将数据打印到控制台。
Counting callbacks is one of the fundamental ways of managing async in Node.
计数回调是管理Node中的异步的基本方法之一。
Rather than doing it yourself, you may find it more convenient to rely on a third-party library such as async or after.
与其自己做这些事情,倒不如你可以更加方便的在async或after之类的第三方库找到。
But for this exercise, try and do it without any external helper library.