<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="then.js"></script>
<script>
// <!-- thenjs第一处,parallel的用法-->
Thenjs.parallel([
function(cb){
var a = [1,1,1,1];
cb(null,a);
},
function(cb){
var b = [2,2,2,2];
cb(null,b);
},
function(cb){
var c = [3,3,3,3];
cb(null,c);
},
function(cb){
var cc = [8,8,8,8,8,8];
var xx = [];
Thenjs.each(cc,function(ecb,p){
xx.push(p*2);
ecb(null,null);
}).then(function(err,ps){
cb(null,xx)
});
}
]).then(function(cb,result){
console.log(result[0]);
console.log(result[1]);
console.log(result[2]);
console.log(result[3]);
});
//模仿查询回调函数
function task(arg,callback){
setTimeout(callback(null,arg),1);
} // <!-- thenjs第二处,eachSeries的用法-->
Thenjs.eachSeries([0, 1, 2], function (cont, value) {
task(value * 2, cont);
}).then(function (cont, result) {
console.log(result);
}); // <!-- thenjs第三处,each的用法-->
Thenjs.each([5, 5, 5], function(ecb,p){
// task(p* 2, ecb);
ecb(null,p*2)
}).then(function (ecb, result) {
console.log(result);
});
//后期继续收集
</script>
</body>
</html>

用的比较频繁的就是parallel的用法

thenjs的应用的更多相关文章

  1. ThenJS

    安装ThenJs:  npm i thenjs 史上最快,与 node callback 完美结合的异步流程控制库 <!doctype html> <html lang=" ...

  2. 2014 Hangjs 见闻流水账第一天

    前言 6月21日~6月22日, 第一次跑远门去参加一个大会(广州 -> 杭州),本来打算,在火车的回来的路上,把这两天的东西记录一下,不过,火车上的环境实在恶劣,同时也高估了自己的专注力,所以, ...

  3. 关于关注和取消关注的nodejs写法

    本例子的关注和取消关注,是通过ajax的方法实现的:nodejs后台写好api接口:响应前台的ajax 先看ajax的代码实现: // 用户关注标签 function subscribe(uid, t ...

  4. express中路由设置的坑-----1

    router.get('/commodities/sortable', utils.logged, function (req, res) { Commodity.find({force_top:tr ...

  5. nodejs项目中的路由写法

    //两种路由写法,一种封装成函数,返回结果,此种方法可以传递参数, "use strict"; var _ = require("lodash"); var e ...

  6. node.js爬虫

    这是一个简单的node.js爬虫项目,麻雀虽小五脏俱全. 本项目主要包含一下技术: 发送http抓取页面(http).分析页面(cheerio).中文乱码处理(bufferhelper).异步并发流程 ...

  7. (转) Read-through: Wasserstein GAN

    Sorta Insightful Reviews Projects Archive Research About  In a world where everyone has opinions, on ...

  8. angular的require模块的使用($requireProvider的作用)

      今天我们学习一下angular的另一个几乎被忽略的模块angular-require 先给出链接地址(git:)   https://github.com/Treri/angular-requir ...

  9. 如何在项目中使用requireJS

    本文主要讲讲如何在一个项目中合理的使用requireJS,来加载js代码,这里是个实际例子,讲解不多, 看详情请连接到:http://www.cnblogs.com/evaling/p/6722760 ...

随机推荐

  1. django之HttpRequest对象

    class HttpRequest[source] 属性 所有的属性都是只读的,除非另有说明 HttpRequest.scheme 字符串(http/https)表示http还是https请求 Htt ...

  2. python作业day4计算器

    思路: 用循环提取最里面的括号,再进行运算 运算时利用正则表达式寻找相应的运算符 先进行乘除,再进行加减 (参考武sir和金角大王的代码) 流程图: 代码: #!/usr/bin/env python ...

  3. centos6.4 ceph安装部署之ceph block device

    1,prelight/preface ceph storage clusterceph block deviceceph filesystemceph object storage 此篇记录ceph ...

  4. jquery 中 fn.apply(this, arguments)是什么函数?有什么作用?能举个例子吗

    function Person(name){ this.name=name; this.sayname=function (){ alert(this.name); } } function Stud ...

  5. Qt on Android:QTableView不显示选中虚框

    在使用 QTableView 或 QTableWidget 时.有时我们不想要选中虚框,能够实现一个 ItemDelegate ,重写 drawFocus() 和 drawCheck()  两个虚函数 ...

  6. C++关注备注部分知识点

    //关注备注部分知识点. #include <iostream> #include <string><span style="white-space:pre&q ...

  7. UC浏览器开发者版调试手机页面

    1 关于RI 目前,在手机上使用浏览器访问网页,无法便捷地进行网页语言调试.手机屏幕相对较小且操作不便,直接在手机上进行网页数据调试不太现实. 因此,我们使用技术将手机网页调试信息分离,实现一种能在大 ...

  8. Android源码大全

    JavaApk-安卓应用游戏APP源码下载 - Android App Games Source Download. http://www.javaapk.com/  700多个 Android 例子 ...

  9. org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session

    出错原因很简单:数据库服务没开,自然就打不开Session了.

  10. JAVA关键字transient

    转载自http://www.cnblogs.com/liuling/archive/2013/05/05/transient.html 1.transient关键字只能修饰变量,而不能修饰方法和类.注 ...