学海网 文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 计算机软件及应用 > Async的流程控制使用文档

Async的流程控制使用文档

Nodejs著名的流程控制库

# Async.js [![Build Status via Travis CI](doc.xuehai.net)](doc.xuehai.net) Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with [Node.js](doc.xuehai.net), it can also be used directly in the browser. Also supports [component](doc.xuehai.net). Async provides around 20 functions that include the usual 'functional' suspects (`map`, `reduce`, `filter`, `each`…) as well as some common patterns for asynchronous control flow (`parallel`, `series`, `waterfall`…). All these functions assume you follow the Node.js convention of providing a single callback as the last argument of your `async` function. ## Quick Examples ```javascript async.map(['file1','file2','file3'], fs.stat, function(err, results){ // results is now an array of stats for each file }); async.filter(['file1','file2','file3'], fs.exists, function(results){ // results now equals an array of the existing files }); async.parallel([ function(){ ... }, function(){ ... } ], callback); async.series([ function(){ ... }, function(){ ... } ]); ``` There are many more functions available so take a look at the docs below for a full list. This module aims to be comprehensive, so if you feel anything is missing please create a GitHub issue for it. ## Common Pitfalls ### Binding a context to an iterator This section is really about `bind`, not about `async`. If you are wondering how to make `async` execute your iterators in a given context, or are confused as to why a method of another library isn't working as an iterator, study this example: ```js // Here is a simple object with an (unnecessarily roundabout) squaring method var AsyncSquaringLibrary = { squareExponent: 2, square: function(number, callback){ var result = Math.pow(number, this.squareExponent); setTimeout(function(){ callback(null, result); }, 200); } }; async.map([1, 2, 3], AsyncSquaringLibrary.square, function(err, result){ // result is [NaN, NaN, NaN] // This fails because the `this.squareExponent` expression in the square // function is not evaluated in the context of AsyncSquaringLibrary, and is // therefore undefined. }); async.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), function(err, result){ // result is [1, 4, 9] // With the help of bind we can attach a context to the iterator before // passing it to async. Now the square function will be executed in its // 'home' AsyncSquaringLibrary context and the value of `this.squareExponent` // will be as expected. }); ``` ## Download The source is available for download from [GitHub](doc.xuehai.net). Alternatively, you can install using Node Package Manager (`npm`): npm install async __Development:__ [async.js](doc.xuehai.net.

第1页

TOP相关主题

  • async false
  • android async http
  • dispatch async
  • ajax async
  • jquery ajax async
  • async true
  • ajax async false
  • nodejs async

我要评论

相关文档

  • 使用DOM管理XML文档

    VB 6.0 内从 部使用 MSXML 的步骤为: ①打开...xDoc.async = False If xDoc.Load("http://www....当为 true(默认值) 文件下载完毕就把控制返回给...

  • jBPM-jPDL学习笔记——流程设计与控制

    jBPM-jPDL 学习笔记——流程设计与控制 作者: 发布...三种节点都可以定义异步处理方式(async 属性): 异步...定义文档是可以直接被 ProcessDefinition 类载入使用的...

  • 利用API播放声音文件

    --- SND_ASYNC 播放 WAV 文件, 然后将控制立即转移回你的应用程序中, 而不管... 可以使用如下的语句: --- Dim ReturnValue As Long --- ReturnSoundValue =...

  • 搭建DataGard--使用文档

    async valid_for=(online_logfiles,primary_role) ...按照上面的步骤再切换回来,也是 OK 的 v$database ...用主库得到控制文件启到到 nomount 然后 alter ...

  • 第6章 使用DOM访问XML文档

    第2章 使用DTD规范XML文档 第3章 结构化程序设计语句... 第3章 使用CSS...表7-4 Document 对象的特有属性 属性 async docType documentEl ement nameSpace...

  • VB中资源文件.res的使用方法详解

    应用程序中都拥有资源文件,这些文件定义使用应用程序...对话框:对话框的资源定义包括样式标志(控制对话框... As Long Public Const SND_ASYNC = &H1& ...

  • 深入浅出nodejs

    解决方案 函数式编程之高阶函数高阶函数: 使用函数作为输入参数或作为返回值的...(EventProxy) Promise/Defered模式(Q模块和when模块) 流程控制库(Async和step) ...

  • 微型计算机技术及应用的复习文档

    控制总线 . 1 数据总线用来传输数据信息,数据总线是...串行通信分为两种方式:异步通信(ASYNC)与同步通信(...逻辑地址:通常程序使用的地址,也叫虚拟地址,包含...

  • Dephi中资源文件使用详解

    ('MyWav' HInstance Snd_ASync or Snd_Memory or ...资源文件的使用步骤为: 1.编写rc脚本文本用记事本...2.资源文件不但可以在标准图形界面下使用还可在控制...

  • Dephi5中资源文件的创建和使用_陈经韬

    ('MyWav' HInstance Snd_ASync or Snd_Memory or ...资源文件的使用步骤为: 1.编写 rc 脚本文本 用...2.资源文件不但可以在标准图形界面下使用还可在控制...

站点地图 | 文档上传 | 侵权投诉 | 手机版
新浪认证  诚信网站  绿色网站  可信网站   非经营性网站备案
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.xuehai.net All Rights Reserved.  email
返回顶部