• PUDN用户
    了解作者
  • JavaScript
    开发工具
  • 15.9MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2015-03-27 11:29
    上传日期
使用node.js开发语言写的dome,因为是刚学的,请大家指正。
Node.rar
内容介绍
# Async.js Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with [node.js](http://nodejs.org), it can also be used directly in the browser. 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'], path.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. ## Download Releases are available for download from [GitHub](http://github.com/caolan/async/downloads). Alternatively, you can install using Node Package Manager (npm): npm install async __Development:__ [async.js](https://github.com/caolan/async/raw/master/lib/async.js) - 17.5kb Uncompressed __Production:__ [async.min.js](https://github.com/caolan/async/raw/master/dist/async.min.js) - 1.7kb Packed and Gzipped ## In the Browser So far its been tested in IE6, IE7, IE8, FF3.6 and Chrome 5. Usage: ```html <script type="text/javascript" src="async.js"></script> <script type="text/javascript"> async.map(data, asyncProcess, function(err, results){ alert(results); }); </script> ``` ## Documentation ### Collections * [each](#each) * [map](#map) * [filter](#filter) * [reject](#reject) * [reduce](#reduce) * [detect](#detect) * [sortBy](#sortBy) * [some](#some) * [every](#every) * [concat](#concat) ### Control Flow * [series](#series) * [parallel](#parallel) * [whilst](#whilst) * [doWhilst](#doWhilst) * [until](#until) * [doUntil](#doUntil) * [waterfall](#waterfall) * [compose](#compose) * [applyEach](#applyEach) * [queue](#queue) * [cargo](#cargo) * [auto](#auto) * [iterator](#iterator) * [apply](#apply) * [nextTick](#nextTick) * [times](#times) * [timesSeries](#timesSeries) ### Utils * [memoize](#memoize) * [unmemoize](#unmemoize) * [log](#log) * [dir](#dir) * [noConflict](#noConflict) ## Collections <a name="forEach" / rel='nofollow' onclick='return false;'> <a name="each" / rel='nofollow' onclick='return false;'> ### each(arr, iterator, callback) Applies an iterator function to each item in an array, in parallel. The iterator is called with an item from the list and a callback for when it has finished. If the iterator passes an error to this callback, the main callback for the each function is immediately called with the error. Note, that since this function applies the iterator to each item in parallel there is no guarantee that the iterator functions will complete in order. __Arguments__ * arr - An array to iterate over. * iterator(item, callback) - A function to apply to each item in the array. The iterator is passed a callback(err) which must be called once it has completed. If no error has occured, the callback should be run without arguments or with an explicit null argument. * callback(err) - A callback which is called after all the iterator functions have finished, or an error has occurred. __Example__ ```js // assuming openFiles is an array of file names and saveFile is a function // to save the modified contents of that file: async.each(openFiles, saveFile, function(err){ // if any of the saves produced an error, err would equal that error }); ``` --------------------------------------- <a name="forEachSeries" / rel='nofollow' onclick='return false;'> <a name="eachSeries" / rel='nofollow' onclick='return false;'> ### eachSeries(arr, iterator, callback) The same as each only the iterator is applied to each item in the array in series. The next iterator is only called once the current one has completed processing. This means the iterator functions will complete in order. --------------------------------------- <a name="forEachLimit" / rel='nofollow' onclick='return false;'> <a name="eachLimit" / rel='nofollow' onclick='return false;'> ### eachLimit(arr, limit, iterator, callback) The same as each only no more than "limit" iterators will be simultaneously running at any time. Note that the items are not processed in batches, so there is no guarantee that the first "limit" iterator functions will complete before any others are started. __Arguments__ * arr - An array to iterate over. * limit - The maximum number of iterators to run at any time. * iterator(item, callback) - A function to apply to each item in the array. The iterator is passed a callback(err) which must be called once it has completed. If no error has occured, the callback should be run without arguments or with an explicit null argument. * callback(err) - A callback which is called after all the iterator functions have finished, or an error has occurred. __Example__ ```js // Assume documents is an array of JSON objects and requestApi is a // function that interacts with a rate-limited REST api. async.eachLimit(documents, 20, requestApi, function(err){ // if any of the saves produced an error, err would equal that error }); ``` --------------------------------------- <a name="map" / rel='nofollow' onclick='return false;'> ### map(arr, iterator, callback) Produces a new array of values by mapping each value in the given array through the iterator function. The iterator is called with an item from the array and a callback for when it has finished processing. The callback takes 2 arguments, an error and the transformed item from the array. If the iterator passes an error to this callback, the main callback for the map function is immediately called with the error. Note, that since this function applies the iterator to each item in parallel there is no guarantee that the iterator functions will complete in order, however the results array will be in the same order as the original array. __Arguments__ * arr - An array to iterate over. * iterator(item, callback) - A function to apply to each item in the array. The iterator is passed a callback(err, transformed) which must be called once it has completed with an error (which can be null) and a transformed item. * callback(err, results) - A callback which is called after all the iterator functions have finished, or an error has occurred. Results is an array of the transformed items from the original array. __Example__ ```js async.map(['file1','file2','file3'], fs.stat, function(err, results){ // results is now an array of stats for each file }); ``` --------------------------------------- <a name="mapSeries" / rel='nofollow' onclick='return false;'> ### mapSeries(arr, iterator, callback) The same as map only the iterator is applied to each item in the array in series. The next iterator is only called once the current one has completed processing. The results array will be in the same order as the original. --------------------------------------- <a name="mapLimit" / rel='nofollow' onclick='return false;'> ### mapLimit(arr, limit, iterator, callback) The same as map only no more than "limit" iterators will be simultaneously running at any time. Note that the items are not processed in batches, so there is no guarantee that the first "limit" iterator functions will complete before any others are started. __Arguments__ * arr - An array to iterate over. * limit - The maximum number of iterators to run at any time. * iterator(item, callback) - A function to apply to each item in the array. The iterator is passed a callback(err, transformed) which must be called once it has completed with an error (which can be null) and a transformed item. * callback(err, results) - A callback which is called after all the iterator functions have finished, or an
评论
    相关推荐
    • node.js:学习 Node.js
      节点.js 学习 Node.js :D
    • 刮擦Node.js Docker映像-Node.js开发
      刮擦Node.js Docker映像最小的Node.js Docker映像。 内容一个静态链接的Node.js二进制文件用于支持本机模块的musl动态链接器节点用户的/ etc / passwd条目图像刮擦Node.js Docker图像最小的Node.js Docker图像。 ...
    • mininode:由Node.js创建的微型Node.js使用Node.js创建的Node.js
      使用Node.js创建的Node.js 印象深刻的是我挑战用Node.js制作迷你Node.js. ...初榨esprima ...抽象语法树(AST) ...执行加法 符的计算器...直到制作计算器和比较运算符的实现为止 变量...变量声明,赋值,参考 ....
    • node.js:学习 node.js
      基于一本叫node.js的教材,学习node.js和服务器开发 要求 节点.js 15.2.1 npm 7.0.10 快速开始 第一个休息服务器 cd Document/ch4 node restServer.js 在控制台勾选“Server is waiting on port 8082”后,用...
    • JavaScript - Node.JS教程系列
      Node.JS是一套使用JavaScript语言的后台。它执行Javascript的速度非常快,性能非常好。是近几年来火的公司首选后台语言之一,同时也是前后台人员争先恐后学习的后台语言。
    • Node.js-Tutorial:Node.js
      Node.js:教程 使用本教程作为学习Node.js的指南。 每个单元都包含带注释的课程,其中包含工作示例。 主题 介绍 大事记 溪流 文件系统操作 上载档案 模组 NPM 表示 快速路线 套接字 使用Redis持久化数据 建议的先决...
    • node-basics:Node.js基础
      Node.js在服务器上使用JavaScript 为什么选择Node.jsNode.js使用异步编程! Web服务器的常见任务是打开服务器上的文件,然后将内容返回给客户端。 这是PHP或ASP处理文件请求的方式: 将任务发送到计算机的...
    • Node.js:Node.js练习和学习
      Node.js 我在此存储库中使用了Node.js,Express.js,Socket.io和Mqtt.js和Mysql。 这里我们有: Node.js和Express.js基础使用Express.js和Socket.io的简单Mqtt客户端使用Express.js和Socket.io的简单聊天应用... ...
    • 了不起的 node .js(smashing node.js javascript everywhere) 示例代码
      了不起的 node .js(smashing node.js javascript everywhere) 示例代码
    • node.js:node.js学习
      node.js node.js研究