zoukankan      html  css  js  c++  java
  • thenjs的应用

     1 <!doctype html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <body>
     8 <script src="then.js"></script>
     9 <script>
    10 //    <!-- thenjs第一处,parallel的用法-->
    11     Thenjs.parallel([
    12         function(cb){
    13             var a = [1,1,1,1];
    14             cb(null,a);
    15         },
    16         function(cb){
    17             var b = [2,2,2,2];
    18             cb(null,b);
    19         },
    20         function(cb){
    21             var c = [3,3,3,3];
    22             cb(null,c);
    23         },
    24         function(cb){
    25             var cc = [8,8,8,8,8,8];
    26             var xx = [];
    27             Thenjs.each(cc,function(ecb,p){
    28                 xx.push(p*2);
    29                 ecb(null,null);
    30             }).then(function(err,ps){
    31                 cb(null,xx)
    32             });
    33         }
    34     ]).then(function(cb,result){
    35         console.log(result[0]);
    36         console.log(result[1]);
    37         console.log(result[2]);
    38         console.log(result[3]);
    39     });
    40 //模仿查询回调函数
    41 function task(arg,callback){
    42     setTimeout(callback(null,arg),1);
    43 }
    44 
    45 
    46 //    <!-- thenjs第二处,eachSeries的用法-->
    47 Thenjs.eachSeries([0, 1, 2], function (cont, value) {
    48     task(value * 2, cont);
    49 }).then(function (cont, result) {
    50     console.log(result);
    51 });
    52 
    53 
    54 
    55 //    <!-- thenjs第三处,each的用法-->
    56 Thenjs.each([5, 5, 5], function(ecb,p){
    57 //    task(p* 2, ecb);
    58     ecb(null,p*2)
    59 }).then(function (ecb, result) {
    60     console.log(result);
    61 });
    62 //后期继续收集
    63 </script>
    64 </body>
    65 </html>

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

    坚持下去就能成功
  • 相关阅读:
    USACO Broken Necklace 通过了
    USACO Broken Necklace
    推荐顺序ACM
    usaco暂时无法访问
    格式
    稳定排序
    归并排序
    浅析Struts1和Struts2的Action线程安全问题
    判别式模型与生成式模型的区别
    远景能源一面
  • 原文地址:https://www.cnblogs.com/suoking/p/5053657.html
Copyright © 2011-2022 走看看