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().
這個(gè)問(wèn)題和前面的問(wèn)題(HTTP COLLECT)是一樣的,你需要使用http.get()。
However, this time you will be provided with three URLs as the first three command-line arguments.
然而,這次你將獲得三個(gè)URL作為前三個(gè)命令行參數(shù)。
You must collect the complete content provided to you by each of the URLs and print it to the console (stdout).
您必須收集每個(gè)URL提供給您的完整內(nèi)容并將其打印到控制臺(tái)(stdout)。
You don't need to print out the length, just the data as a String; one line per URL.
你不需要打印出長(zhǎng)度,只需將數(shù)據(jù)打印為字符串; 每個(gè)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.
問(wèn)題在于,你必須按照提供給你的URL和命令行參數(shù)相同的順序打印出來(lái)。
─────────────────────────────────────────────────────────────────────────────
HINTS
Don't expect these three servers to play nicely!
不要期望這三臺(tái)服務(wù)器擔(dān)任的很好!
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.
他們不會(huì)按照你希望的順序給你完整的答復(fù),所以你不能天真地打印輸出你取得的東西,因?yàn)樗麄儠?huì)發(fā)生故障。
You will need to queue the results and keep track of how many of the URLs have returned their entire contents.
您需要對(duì)結(jié)果進(jìn)行排序然后跟蹤有多少個(gè)網(wǎng)址已經(jīng)返回了他們的全部?jī)?nèi)容。
Only once you have them all, you can print the data to the console.
只要你全部獲得了他們,你就能將數(shù)據(jù)打印到控制臺(tái)。
Counting callbacks is one of the fundamental ways of managing async in Node.
計(jì)數(shù)回調(diào)是管理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之類的第三方庫(kù)找到。
But for this exercise, try and do it without any external helper library.