# Async.js
[![Build Status via Travis CI](https://travis-ci.org/caolan/async.svg?branch=master)](https://travis-ci.org/caolan/async)
[![NPM version](http://img.shields.io/npm/v/async.svg)](https://www.npmjs.org/package/async)
[![Coverage Status](https://coveralls.io/repos/caolan/async/badge.svg?branch=master)](https://coveralls.io/r/caolan/async?branch=master)
[![Join the chat at https://gitter.im/caolan/async](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/caolan/async?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
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) and installable via `npm install async`,
it can also be used directly in the browser.
Async is also installable via:
- [bower](http://bower.io/): `bower install async`
- [component](https://github.com/component/component): `component install
caolan/async`
- [jam](http://jamjs.org/): `jam install async`
- [spm](http://spmjs.io/): `spm install async`
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 <sub>[(StackOverflow)](http://stackoverflow.com/questions/tagged/async.js)</sub>
### Synchronous iteration functions
If you get an error like `RangeError: Maximum call stack size exceeded.` or other stack overflow issues when using async, you are likely using a synchronous iterator. By *synchronous* we mean a function that calls its callback on the same tick in the javascript event loop, without doing any I/O or using any timers. Calling many callbacks iteratively will quickly overflow the stack. If you run into this issue, just defer your callback with `async.setImmediate` to start a new call stack on the next tick of the event loop.
This can also arise by accident if you callback early in certain cases:
```js
async.eachSeries(hugeArray, function iterator(item, callback) {
if (inCache(item)) {
callback(null, cache[item]); // if many items are cached, you'll overflow
} else {
doSomeIO(item, callback);
}
}, function done() {
//...
});
```
Just change it to:
```js
async.eachSeries(hugeArray, function iterator(item, callback) {
if (inCache(item)) {
async.setImmediate(function () {
callback(null, cache[item]);
});
} else {
doSomeIO(item, callback);
//...
```
Async guards against synchronous functions in some, but not all, cases. If you are still running into stack overflows, you can defer as suggested above, or wrap functions with [`async.ensureAsync`](#ensureAsync) Functions that are asynchronous by their nature do not have this problem and don't need the extra callback deferral.
If JavaScript's event loop is still a bit nebulous, check out [this article](http://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/) or [this talk](http://2014.jsconf.eu/speakers/philip-roberts-what-the-heck-is-the-event-loop-anyway.html) for more detailed information about how it works.
### Multiple callbacks
Make sure to always `return` when calling a callback early, otherwise you will cause multiple callbacks and unpredictable behavior in many cases.
```js
async.waterfall([
function (callback) {
getSomething(options, function (err, result) {
if (err) {
callback(new Error("failed getting something:" + err.message));
// we should return here
}
// since we did not return, this callback still will be called and
// `processData` will be called twice
callback(null, result);
});
},
processData
], done)
```
It is always good practice to `return callback(err, result)` whenever a callback call is not the last statement of a function.
### 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](https://github.com/caolan/async/blob/master/lib/async.js).
Alternatively, you can install using Node Package Manager (`npm`):
npm install async
As well as using Bower:
bower install async
__Development:__ [async.js](https://github.com/caolan/async/raw/master/lib/async.js) - 29.6kb Uncompressed
## In the Browser
So far it's 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
Some functions are also available in the following forms:
* `<name>Series` - the same as `<name>` but runs only a single async operation at a time
* `<name>Limit` - the same as `<name>` but runs a maximum of `limit` async operations at a time
### Collections
* [`each`](#each), `eachSeries`, `eachLimit`
* [`forEachOf`](#forEachOf), `forEachOfSeries`, `forEachOfLimit`
* [`map`](#map), `mapSeries`, `mapLimit`
* [`filter`](#filter), `filterSeries`, `filterLimit`
* [`reject`](#reject), `rejectSeries`, `rejectLimit`
* [`reduce`](#reduce), [`reduceRight`](#reduceRight)
* [`detect`](#detect), `detectSeries`, `detectLimit`
* [`sortBy`](#sortBy)
* [`some`](#some), `someLimit`
* [`every`](#every), `everyLimit`
* [`concat`](#concat), `concatSeries`
### Control Flow
* [`series`](#seriestasks-callback)
* [`parallel`](#parallel), `parallelLimit`
* [`whilst`](#whilst), [`doWhilst`](#doWhilst)
* [`until`](#until), [`doUntil`](#doUntil)
* [`during`](#during), [`doDuring`](#doDuring)
* [`forever`](#forever)
* [`waterfall`](#waterfall)
* [`compose`](#compose)
* [`seq`](#seq)
* [`applyEach`](#applyEach), `applyEachSeries`
* [`queue`](#queue), [`priorityQueue`](#priorityQueue)
* [`cargo`](#cargo)
* [`auto`](#auto)
* [`retry`](#retry)
* [`iterator`](#iterator)
* [`times`](#times), `timesSeri
没有合适的资源?快使用搜索试试~ 我知道了~
中国非物质遗产网站前端设计项目+html+css+js+jquery+ajax
共1884个文件
js:543个
jpg:264个
png:179个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 152 浏览量
2023-06-07
11:12:15
上传
评论
收藏 48.55MB RAR 举报
温馨提示
非物质遗产项目设计非常高端大气,设计优美高雅,内容丰富,包含了中国的绝大多数非物质遗产及图片展示,主要内容: 1、中国戏曲介绍设计,如昆曲,京剧,越剧,包括要闻,新闻列表,戏曲名家,戏曲活动展示等页面的设计 2、中国茶艺,包括茶艺详情,茶技艺,新闻列表,点赞,评论等页面设计 3、资源介绍及设计,如太极拳,宣纸传统制作艺术,少数民族各种风俗习惯及特色产品及详情页等设计,书法,雕刻,中医,美术,乐曲 4、学术论坛设计,包括论坛、调研、访谈等页面设计 5、非遗商城设计,商城,商品详情,购购物车等页面设计 6、其他功能,如首页设计,首页天气预报等功能,使i用ajax功能获取天气数据,节气等 使用技术: html + css + js jquery+ less+ajax
资源推荐
资源详情
资源评论
收起资源包目录
中国非物质遗产网站前端设计项目+html+css+js+jquery+ajax (1884个子文件)
07111488d6a4b5055496b5dcbb43e7218a1d29 117B
0bb507085a49f7968512b45973fd195bab445e 115B
1812b1203bf73044e764708fabb52505 517KB
1eb66386fd9db92ef645d2928f3ec8f7a7aaf4 210B
201b72ab42a704b0713277b89f555809e0d324 710B
2241f17a85630578ef9ae1c6a66c3ffb49f7c1 1KB
29138c3c93c5975bd5b62d148f4e2fb8e891cb 505B
2c2a76d7532ad5df9ac53ff20b5b24ff 517KB
341500c82a2a845d4c5625314f6a5885b31604 119B
4243edc8c8883aa8629e3f1be4adf2227e37bc 115B
44642846e02656cb869338e232723cef 517KB
47cf2be999c9a2237230c0a13b11b934bf688b 996B
4b3defd39036abbc1c5597298c3f820e193245 157B
4d10014f5a5fc1171bb72e1dbc0b8038961a66 738B
52640e5ccd470224e32e6ed1fa17d977 517KB
5674cdfe0fbb66689c1641db9d27a22d47c815 146B
5b0030f764727e50cfed1a66586b09c3a3a7f9 384B
5d4f6326c3005e01f222040f005ed015048ced 334B
5e72423a808ae4a48c8b63041a32dd246f8fce 119B
6064b282ef715e5dbee7179e2ad4b437af4495 204B
609de1c704f32d1c017235e7e0970130f21159 1KB
714abb6c656aafd4e32fcfdfd472ef28399244 1KB
795264f61dc23361ad2fe323c70958f086ee2a 843B
7fa64dcf7afca5b9b018352afafc4b139c3581 201B
83446ad1cea0c9ed25c8645b2fafdc2da7b56a 1KB
83bd9033b232899bac98c28d7f17dcc5c19fbc 115B
8bfca707c2061f7cc9a2747dcd9e58f2d05a23 906B
8f36879d573a5f859a0e6dc1cd7e04df290b79 118B
8fb0245d9e298f4937cb1ece6d028b269dbe2c 739B
9887aa54bc346091afa640879d79f9776e224e 123B
9b008ae7e923cc8acbcdf61bf2ab389b682599 147B
9ee783e29ad8126635b9adfd902436d68928bb 2KB
a129af796874cda27228ff6f95a6ed9801c594 2KB
a5ffbefa14377bb2efcdaa01afb882a6 517KB
afde77fd7db941302ceb843ac8d1a7a0413fd5 146B
article 338B
article 147B
article 41B
article 41B
b056f6682e88cea7a3cb1052ad179818ef0c3d 158B
b11a5d5140d4f18be985cb0102f3a6db 517KB
bcc0ae715a1f5891f324506857afc3b977c37d 83B
bcrypt 877B
range.bnf 619B
c3ba7a8dbcc44607c8d3748095775dd6f9018d 1KB
c6920280593e0133700e4d428c023f9f6c0614 178B
c6b18de0b2085e78453eed03d5ff7cbaee840b 1KB
changelog 1KB
mkdirp.cmd 277B
semver.cmd 277B
mime.cmd 271B
CODEOWNERS 11B
COMMIT_EDITMSG 40B
config 551B
light.css 207KB
dark.css 207KB
bootstrap.css 185KB
bootstrap.css 185KB
bootstrap.css 119KB
layui.css 91KB
skin.min.css 43KB
fontawesome-all.min.css 36KB
skin.mobile.min.css 27KB
swiper-bundle.css 18KB
swiper-bundle.min.css 16KB
style.css 16KB
style.css 16KB
styles.css 15KB
layer.css 14KB
main.css 12KB
indexs.css 11KB
index.css 11KB
dl.css 10KB
base.css 10KB
layui.mobile.css 10KB
magicBtn.min.css 9KB
demo.css 8KB
资源.css 7KB
laydate.css 7KB
main.css 7KB
戏曲.css 6KB
资源.css 6KB
default.css 6KB
htmleaf-demo.css 6KB
htmleaf-demo.css 6KB
htmleaf-demo.css 6KB
商城.css 6KB
magicBtn.css 6KB
default.css 6KB
visualblocks.css 5KB
cropper.css 5KB
戏曲.css 5KB
图集.css 5KB
影音.css 5KB
非遗商城.css 4KB
学术.css 4KB
图集.css 4KB
content.min.css 4KB
index.css 3KB
展览.css 3KB
共 1884 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
资源评论
CSDN专家-赖老师(软件之家)
- 粉丝: 4710
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功