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. video元素和audio元素

    内容: 1.video元素 2.audio元素 注:这两个元素均是HTML5新增的元素 1.video元素 (1)用途 <video> 标签定义视频,比如电影片段或其他视频流 (2)标签属 ...

  2. python输入输出及变量

    知识内容: 1.python输出及注释 2.变量及常量 3.python用户输入 4.Hello,World程序 一.python输出及注释 1.python输出 在python2和python3中的 ...

  3. 9.简单理解ajax

    #### post 请求需要发送一个header setRequestHeader('Content-Type','application/x-www-form-urlencoded') post请求 ...

  4. html:模板

    http://www.mycodes.net/code_previewmap.php?id=3461 http://www.17sucai.com/pins/4120.html  欧美风格的CMS企业 ...

  5. linux 下创建文本的方法

    1.   打开终端,输入  vi  1.txt 输入:wq 文本创建成功 2.  打开终端,输入  vim  1.txt 输入:wq 文本创建成功 3. 打开终端 , 输入 touch  1.txt ...

  6. gevent 实现单线程下的socket链接

    通过gevent实现socket的多并发 server 端: import geventfrom gevent import socket, monkey monkey.patch_all() #进行 ...

  7. vector实现(只能装入string)

    #include<iostream> #include<string> #include<memory> #include<utility> using ...

  8. Python Spider 抓取猫眼电影TOP100

    """ 抓取猫眼电影TOP100 """ import re import time import requests from bs4 im ...

  9. cobbler配置解析

    1.Cobbler命令说明: 命令名称 命令用途 cobbler check 检查cobbler配置 cobbler list 列出所有的cobbler元素 cobbler report 列出元素的详 ...

  10. 关于eval()函数处理后台返回的json数据

    对于服务器返回的JSON字符串,如果jquery异步请求没做类型说明,或者以字符串方式接受,那么需要做一次对象化处理,方式不是太麻烦,就是将该字符串放于eval()中执行一次.这种方式也适合以普通ja ...