UNPKG

workshopper-browser-guide

Version:

Create an html browser version of the exercise descriptions

86 lines (80 loc) 4.19 kB
<!doctype html> <html class="no-js" lang="zh-cn"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>learnyounode Guide</title> <meta name="description" content="learn git and github"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="assets/css/style.css"> <link rel="stylesheet" href="assets/css/code.css"> <link href='assets/fonts/fonts.css' rel='stylesheet' type='text/css'> </head> <body> <!--[if lt IE 8]> <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> <header class="site-header"> <div class="nav u-posFixed"> <ul class="nav-lang"> <li><a href="juggling_async.html" >English</a></li> <li><a href="juggling_async.es.html" >Español</a></li> <li><a href="juggling_async.ja.html" >日本語</a></li> <li><a href="juggling_async.pt-br.html" >Português (Brasil)</a></li> <li><a href="juggling_async.ru.html" >Русский</a></li> <li><a href="juggling_async.zh-cn.html" >中文 (中国)</a></li> <li><a href="juggling_async.zh-tw.html" >中文 (臺灣)</a></li> </ul> <div class="wrap-width u-textCenter"> <a href="http_collect.zh-cn.html" <span class="u-floatLeft hand"></span> </a> <a class="filledblock" href="index.zh-cn.html">learnyounode</a> <a href="time_server.zh-cn.html" <span class="u-floatRight hand"></span> </a> </div> </div> <div class="wrapper"> <div class="u-floatLeft"> <span class="all-caps">CHALLENGE</span> <h2 class="challenge-name">玩转异步</h2> </div> <div class="u-floatRight u-textRight"> <span class="all-caps">NUMBER</span> <h2 class="challenge-name">9 / 13</h2> </div> </div> </header> <div class="wrapper"> <p>这次的问题和之前的问题(HTTP 收集器)很像,也是需要使用到 <code>http.get()</code> 方法。然而,这一次,将有<strong>三个</strong> URL 作为前三个命令行参数提供给你。</p> <p>你需要收集每一个 URL 所返回的完整内容,然后将它们在终端(标准输出 stdout)打印出来。这次你不需要打印出这些内容的长度,仅仅是内容本身即可(字符串形式);每个 URL 对应的内容为一行。重点是你<strong>必须</strong>按照这些 URL 在参数列表中的顺序将相应的内容排列打印出来才算完成。</p> <hr> <h2 id="-">提示</h2> <p>不要期待这三台服务器能好好的一起玩耍!他们可能不会把完整的响应的结果按照你希望的顺序返回给你,所以你不能天真地只是在收到响应后直接打印出来,因为这样做的话,他们的顺序可能会乱掉。</p> <p>你需要去跟踪到底有多少 URL 完整地返回了他们的内容,然后用一个队列存储起来。一旦你拥有了所有的结果,你才可以把它们打印到终端。</p> <p>对回调进行计数是处理 Node 中的异步的基础。比起你自己去做,你会发现去依赖一个第三方的模块或者库会更方便,比如 <a href="http://npm.im/async">async</a> 或者 <a href="http://npm.im/after">after</a>。不过,在本次练习中,你应该尝试自己去解决,而不是依赖外部的模块。</p> <hr> <div class="prenext"> <div class="u-floatLeft"> <a href="http_collect.zh-cn.html" class="u-inline-block all-caps">HTTP 收集器 <div></div> </a> </div> <div class="u-textRight u-floatRight"> <a href="time_server.zh-cn.html" class="u-inlineBlock all-caps">授时服务器 <div></div> </a> </div> </div> <footer> <!-- <ul> <li class="all-caps"><a href="index.html"><strong>Challenges</strong></a></li> <li class="all-caps"> <a href="https://github.com/rvagg/learnyounode/issues/new" target="_blank">Open an Issue</a> </li> </ul> --> </footer> </div> </body> </html>