@JunQiu
2018-09-18T17:35:10.000000Z
字数 1608
阅读 1006
summary_2018/06
language_node
### 批处理的串行执行
async function logInOrder(urls) {
for (const url of urls) {
const response = await fetch(url);
console.log(await response.text());
}
}
### 批处理的并发处理
async function handleId (id) {
// ... do somthing or throw Error
}
async function HandleIds (ids) {
const promises = ids.map(handleId)
await Promise.all(promises)
}
### 子任务失败处理
//容忍子任务失败(不打乱子任务的继续执行,应该捕获错误,进行后续处理)
async function handleId (id) {
// ... do somthing or throw Error
}
async function HandleIds (ids) {
const promises = ids
.map(handleId)
.catch(err => err) // return the error, do not throw
const results = await Promise.all(promises)
// now you can analyze and summary the results further
}
//不用允许子任务失败
考虑任务失败的情况,比如错误其它任务的处理,回滚机制,视具体情况而定。
node_pro_dev环境(约定标准)
node_var_let_const(ES6)