[关闭]
@JunQiu 2018-09-18T09:35:10.000000Z 字数 1608 阅读 890

var_let_const、node批处理(串/并行)、node(pro、dev环境)

summary_2018/06 language_node


1、日常工作

2、技术学习

  1. ### 批处理的串行执行
  2. async function logInOrder(urls) {
  3. for (const url of urls) {
  4. const response = await fetch(url);
  5. console.log(await response.text());
  6. }
  7. }
  8. ### 批处理的并发处理
  9. async function handleId (id) {
  10. // ... do somthing or throw Error
  11. }
  12. async function HandleIds (ids) {
  13. const promises = ids.map(handleId)
  14. await Promise.all(promises)
  15. }
  16. ### 子任务失败处理
  17. //容忍子任务失败(不打乱子任务的继续执行,应该捕获错误,进行后续处理)
  18. async function handleId (id) {
  19. // ... do somthing or throw Error
  20. }
  21. async function HandleIds (ids) {
  22. const promises = ids
  23. .map(handleId)
  24. .catch(err => err) // return the error, do not throw
  25. const results = await Promise.all(promises)
  26. // now you can analyze and summary the results further
  27. }
  28. //不用允许子任务失败
  29. 考虑任务失败的情况,比如错误其它任务的处理,回滚机制,视具体情况而定。
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注