Here's the official solution in case you want to compare notes:

 var http = require('http')
var bl = require('bl')
var results = []
var count = 0 function printResults () {
for (var i = 0; i < 3; i++)
console.log(results[i])
} function httpGet (index) {
http.get(process.argv[2 + index], function (response) {
response.pipe(bl(function (err, data) {
if (err)
return console.error(err) results[index] = data.toString()
count++ if (count == 3)
printResults()
}))
})
} for (var i = 0; i < 3; i++)
httpGet(i)

[freeCodeCamp] solution to JUGGLING ASYNC的更多相关文章

  1. [freeCodeCamp] solution to HTTP JSON API SERVER passed!

    var http = require('http') var url = require('url') function parsetime (time) { return { hour: time. ...

  2. 编程概念--使用async和await的异步编程

    Asynchronous Programming with Async and Await You can avoid performance bottlenecks and enhance the ...

  3. 图与例解读Async/Await

    JavaScript ES7的async/await语法让异步promise操作起来更方便.如果你需要从多个数据库或者接口按顺序异步获取数据,你可能最终写出一坨纠缠不清的promise与回调.然而使用 ...

  4. Ubuntu 12.04 LTS 及ubuntu14.10 -- NFS安装

    在Linux 服务器上配置好NFS 根文件系统后,在单板侧挂载NFS 文件系统,具体操作如下:ifconfig eth0 hw ether 00:10:85:18:01:84 /*配置MAC地址*/i ...

  5. nodeschool.io 9

    ~~ JUGGLING ASYNC ~~ 其实就是一个循环,在循环里面输出的顺序,和排列后在外面的顺序不一样,这是为什么呢? 用第三方async包,直接报错了…… This problem is th ...

  6. HttpContext.Current and Web Api

    Using HttpContext.Current in WebApi is dangerous because of async HttpContext.Current gets the curre ...

  7. A complex 16-Level XSS Challenge

    A complex 16-Level XSS Challenge, held in summer 2014 (+1 Hidden Level) Index Level 0 Level 1 Level ...

  8. Async IO

    I was recently reading a series on “Write Sequential Non-Blocking IO Code With Fibers in NodeJS” by  ...

  9. Async All the Way

    Asynchronous code reminds me of the story of a fellow who mentioned that the world was suspended in ...

随机推荐

  1. html大小写问题

    js中变量名,函数,关键字都区分大小写,如var i;和var I;是两个不同的变量. css中定义的元素名称不区分大小写的. html中,标签和标签属性统一使用小写形式,固有属性也一律使用小写,自定 ...

  2. relocation error: /usr/lib64/libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference 问题解决

    在建立一个错误的软连接到ld-linux-x86-64.so.2时,悲剧就这么发生了.此时大部分命令都不能使用,SSH当然也不能登录了.这个时候一定不要退出终端. 有人说那就把软连接复原吧,可是ln也 ...

  3. Where is virtualenvwrapper.sh after pip install?

      I'm trying to setup virtualenvwrapper on OSX, and all the instructions and tutorials I've found te ...

  4. svn快速安装

    windows版本控制系统. 用VisualSVN server 服务端和 TortoiseSVN客户端搭配使用 软件下载 VisualSVN-Server:http://subversion.apa ...

  5. C语言中字符串存储方法

    众所周知,C语言中没有数据类型能够存储字符串, char数据类型仅仅能够存储一个字符的数据,那么在C语言中关于存储字符串这一难题我们改何去何从呢? 下面将详述相关的字符串存储方法; 1,使用字符数组存 ...

  6. jQuery ajax - serializeArray() 方法

    定义和用法 serializeArray() 方法通过序列化表单值来创建对象数组(名称和值). 您可以选择一个或多个表单元素(比如 input 及/或 textarea),或者 form 元素本身. ...

  7. leetcode942

    public class Solution { public int[] DiStringMatch(string S) { var len = S.Length; ; var max = len; ...

  8. Maven 异常

    Archive for required library: '*****org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar' in pr ...

  9. body{font-size: 62.5%;} 解释

    为什么body{font-size: 62.5%;} 2012-10-25 16:15 16778人阅读 评论(0) 收藏 举报  分类: css问题(17)  在网页设计中我们经常看见body{fo ...

  10. python contextmananger装饰器与with

    如果想自定义一个类或者函数使用with语句,除了在类中自己定义__enter__()方法和__exit__()方法外,还可以使用contextmananger装饰器. contextmananger装 ...