# 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, forEach…) 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
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:
<script type="text/javascript" src="async.js"></script>
<script type="text/javascript">
async.map(data, asyncProcess, function(err, results){
alert(results);
});
</script>
## Documentation
### Collections
* [forEach](#forEach)
* [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)
* [until](#until)
* [waterfall](#waterfall)
* [queue](#queue)
* [auto](#auto)
* [iterator](#iterator)
* [apply](#apply)
* [nextTick](#nextTick)
### Utils
* [memoize](#memoize)
* [unmemoize](#unmemoize)
* [log](#log)
* [dir](#dir)
* [noConflict](#noConflict)
## Collections
<a name="forEach" />
### forEach(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 forEach 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 which must be called once it has completed.
* callback(err) - A callback which is called after all the iterator functions
have finished, or an error has occurred.
__Example__
// assuming openFiles is an array of file names and saveFile is a function
// to save the modified contents of that file:
async.forEach(openFiles, saveFile, function(err){
// if any of the saves produced an error, err would equal that error
});
---------------------------------------
<a name="forEachSeries" />
### forEachSeries(arr, iterator, callback)
The same as forEach 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" />
### forEachLimit(arr, limit, iterator, callback)
The same as forEach only the iterator is applied to batches of items in the
array, in series. The next batch of iterators is only called once the current
one has completed processing.
__Arguments__
* arr - An array to iterate over.
* limit - How many items should be in each batch.
* iterator(item, callback) - A function to apply to each item in the array.
The iterator is passed a callback which must be called once it has completed.
* callback(err) - A callback which is called after all the iterator functions
have finished, or an error has occurred.
__Example__
// Assume documents is an array of JSON objects and requestApi is a
// function that interacts with a rate-limited REST api.
async.forEachLimit(documents, 20, requestApi, function(err){
// if any of the saves produced an error, err would equal that error
});
---------------------------------------
<a name="map" />
### 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 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__
async.map(['file1','file2','file3'], fs.stat, function(err, results){
// results is now an array of stats for each file
});
---------------------------------------
<a name="mapSeries" />
### 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="filter" />
### filter(arr, iterator, callback)
__Alias:__ select
Returns a new array of all the values which pass an async truth test.
_The callback for each iterator call only accepts a single argument of true or
false, it does not accept an error argument first!_ This is in-line with the
way node libraries work with truth tests like path.exists. This operation is
performed in parallel, but the results array will be in the same order as the
original.
__Arguments__
* arr - An array to iterate over.
* iterator(item, callback) - A truth test to apply to each item in the array.
The iterator is passed a callback which must be called once it has completed.
* callback(results) - A callback which is called after all the iterator
functions have finished.
__Example__
async.filter(['file1','file2','file3'], path.exists, function(results){
// results now equals an array of the existing files
});
---------------------------------------
<a name="filterSeries" />
### filterSeries(arr, iterator, callback)
__alias:__ selectSeries
The same as filter 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 arra
没有合适的资源?快使用搜索试试~ 我知道了~
国际化方案.zip
共837个文件
js:537个
json:58个
md:41个
需积分: 3 0 下载量 131 浏览量
2024-01-15
10:16:06
上传
评论
收藏 2MB ZIP 举报
温馨提示
方案是为解决特定问题或达成特定目标而制定的一系列计划或步骤。它的作用是提供一种系统性的方法,以有效地应对挑战、优化流程或实现目标。以下是方案的主要作用: 问题解决: 方案的核心目标是解决问题。通过系统性的规划和执行,方案能够分析问题的根本原因,提供可行的解决方案,并引导实施过程,确保问题得到合理解决。 目标达成: 方案通常与明确的目标相关联,它提供了一种达成这些目标的计划。无论是企业战略、项目管理还是个人发展,方案的制定都有助于明确目标并提供达成目标的路径。 资源优化: 方案在设计时考虑了可用资源,以最大化其效用。通过明智的资源分配,方案可以在有限的资源条件下实现最大的效益,提高效率并减少浪费。 风险管理: 方案通常会对潜在的风险进行评估,并制定相应的风险管理策略。这有助于减轻潜在问题的影响,提高方案的可行性和可持续性。 决策支持: 方案提供了决策者所需的信息和数据,以便做出明智的决策。这种数据驱动的方法有助于减少不确定性,提高决策的准确性。 团队协作: 复杂的问题通常需要多个人的协同努力。方案提供了一个共同的框架,帮助团队成员理解各自的职责和任务,促进协作并确保整个团队朝着共同的目标努力。 监控与评估: 方案通常包括监控和评估的机制,以确保实施的有效性。通过定期的评估,可以及时调整方案,以适应变化的环境或新的挑战。 总体而言,方案的作用在于提供一种有序、有计划的方法,以解决问题、实现目标,并在实施过程中最大化资源利用和风险管理。
资源推荐
资源详情
资源评论
收起资源包目录
国际化方案.zip (837个子文件)
nodeunit.1 2KB
AUTHORS 403B
AUTHORS 356B
AUTHORS 310B
benchmark-native.c 613B
nodelint.cfg 239B
uglifyjs.cmd 141B
nodeunit.cmd 139B
nopt.cmd 129B
tap.cmd 125B
ca.cnf 580B
server.cnf 547B
mock_coffee_module.coffee 64B
squid.conf 2KB
COPYING 11KB
ca.crl 0B
ca.crt 1009B
npm-ca.crt 936B
server.crt 920B
test.crt 847B
ca.csr 777B
server.csr 599B
main.css 18KB
mocha.css 2KB
docstyle.css 2KB
nodeunit.css 1KB
prettify-min.css 675B
qs.css 0B
strict.dtd 34KB
junit.xml.ejs 725B
list.ejs 128B
spinner.gif 3KB
.gitignore 2KB
.gitignore 6B
.gitmodules 283B
.gitmodules 207B
bench.gnu 6KB
README.html 38KB
GoogleClientLogin.html 29KB
index.js.html 12KB
README.html 8KB
CHANGES.html 6KB
index.html 4KB
test.html 914B
index.html 559B
test.html 375B
test.html 338B
index.html 237B
index.html 216B
index.html 216B
index.html 216B
index.html 216B
test.html 138B
client.html 71B
googledoodle.jpg 38KB
unicycle.jpg 19KB
unicycle.jpg 19KB
jquery.js 231KB
bs.js 178KB
process.js 87KB
mocha.js 81KB
nodeunit.js 61KB
parse-js.js 53KB
q.js 44KB
index.js 39KB
expect.js 33KB
sax.js 30KB
minimatch.js 28KB
server.js 25KB
index.js 22KB
async.js 21KB
async.js 18KB
glob.js 18KB
prettify-min.js 17KB
json2.js 17KB
nopt.js 17KB
uri.js 16KB
testparser.js 15KB
basic.js 15KB
tap-runner.js 13KB
index.js 12KB
index.js 12KB
tap-assert.js 12KB
index.js 11KB
assert.js 11KB
Transformer.js 10KB
server.js 10KB
ejs.js 10KB
apidocs.js 10KB
defaults.js 9KB
index.js 9KB
index.js 9KB
graceful-fs.js 9KB
index.js 9KB
index.js 8KB
client.js 8KB
index.js 8KB
xml2js.js 8KB
core.js 8KB
index.js 7KB
共 837 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
JJJ69
- 粉丝: 6278
- 资源: 5773
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功