[freeCodeCamp] solution to JUGGLING ASYNC
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的更多相关文章
- [freeCodeCamp] solution to HTTP JSON API SERVER passed!
var http = require('http') var url = require('url') function parsetime (time) { return { hour: time. ...
- 编程概念--使用async和await的异步编程
Asynchronous Programming with Async and Await You can avoid performance bottlenecks and enhance the ...
- 图与例解读Async/Await
JavaScript ES7的async/await语法让异步promise操作起来更方便.如果你需要从多个数据库或者接口按顺序异步获取数据,你可能最终写出一坨纠缠不清的promise与回调.然而使用 ...
- Ubuntu 12.04 LTS 及ubuntu14.10 -- NFS安装
在Linux 服务器上配置好NFS 根文件系统后,在单板侧挂载NFS 文件系统,具体操作如下:ifconfig eth0 hw ether 00:10:85:18:01:84 /*配置MAC地址*/i ...
- nodeschool.io 9
~~ JUGGLING ASYNC ~~ 其实就是一个循环,在循环里面输出的顺序,和排列后在外面的顺序不一样,这是为什么呢? 用第三方async包,直接报错了…… This problem is th ...
- HttpContext.Current and Web Api
Using HttpContext.Current in WebApi is dangerous because of async HttpContext.Current gets the curre ...
- 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 ...
- Async IO
I was recently reading a series on “Write Sequential Non-Blocking IO Code With Fibers in NodeJS” by ...
- Async All the Way
Asynchronous code reminds me of the story of a fellow who mentioned that the world was suspended in ...
随机推荐
- Laravel 5.4: 特殊字段太长报错
laravel 5.4 改变了默认的数据库字符集,现在utf8mb4包括存储emojis支持.如果你运行MySQL v5.7.7或者更高版本,则不需要做任何事情. 当你试着在一些MariaDB或者一些 ...
- centos7.3安装zip,unzip
安装命令: yum install -y unzip zip
- WindowBrush
m_Element.Fill = SystemColors.WindowBrush; BorderBrush="{x:Static SystemColors.WindowBrush}&quo ...
- 数据库中查询json 样式的值的sql语句
参考:http://www.lnmp.cn/mysql-57-new-features-json.html 方式一: 可以查到json中的Key:value SELECT * FROM EDI.edi ...
- CentOS 7 基础命令安装
https://my.oschina.net/u/1428349/blog/288708 1. ifconfig安装 > yum install net-tools 临时变量(可以直接使用sbi ...
- python 冷知识点
# int could accept parameters in bool type.int(True) # result is 1 int(False) # result is 0 reprlib. ...
- 转载:mysql binlog同步redis
ref: https://wenku.baidu.com/view/5d9d04ac6394dd88d0d233d4b14e852458fb39c4.html
- Kotlin语言学习笔记(5)
委托模式(Delegation) 类的委托 interface Base { fun print() } class BaseImpl(val x: Int) : Base { override fu ...
- 关于如何以编程的方式执行TestNG
1.如果需要加入一个一个的类 public static void main(String args[]){ TestNG tng = new TestNG(); tng.SetTestClasses ...
- OpenCv 人脸识别 基础
#include <opencv2\opencv.hpp> #include <iostream> using namespace std; int main() { // 摄 ...