zoukankan      html  css  js  c++  java
  • async

    用async比用promise爽多了

    var async = require('async');
    var fs = require('fs');
    
    async.waterfall([
            function(callback) {
                fs.readFile('./1.txt', 'utf-8', function(err, data) {
                    console.log('1: ', data);
                    callback(null, data);
                });
            },
            function(arg, callback) {
                console.log('2: ', arg);
                fs.readFile('./2.txt', 'utf-8', function(err, data) {
                    callback(null, arg + data, 'haha');
                });
            },
            function(arg, arg2, callback) {
                console.log('3: ', arg, arg2);
                fs.readFile('./3.txt', 'utf-8', function(err, data) {
                    callback(null, arg + data);
                });
            }
        ],
        function(err, result) {
            if(err) {
                console.log('err: ' + err);
            } else if(result) {
                console.log('result: ' + result);
            } else {
                console.log('async error!');
            }
        });
  • 相关阅读:
    UIImageView变灰
    IOS 瀑布流
    IOS9适配 MARK
    MAC PHP MARK
    IOS第三方库 MARK
    IOS聊天对话界面
    UILabel自适应宽度的函数详解
    UIControl的使用
    IOS @2X.png
    自定义UIAlertView
  • 原文地址:https://www.cnblogs.com/lswit/p/5378679.html
Copyright © 2011-2022 走看看