async/await
来源:互联网 发布:淘宝宝贝批量下载 编辑:程序博客网 时间:2024/05/22 06:32
async/await - 8.在for循环中正确的使用await
const fetch = require('node-fetch')const bluebird = require('bluebird')async function getZhihuColumn(id) { await bluebird.delay(1000) const url = `https://zhuanlan.zhihu.com/api/columns/${id}` const response = await fetch(url) return await response.json()}
循环中的串行
const showColumnInfo = async() => { console.time('showColumnInfo') const names = ['qianduanzhidian', 'FrontendMagazine'] for (const name of names) { const column = await getZhihuColumn(name) console.log(`name:${column.name}`) console.log(`description:${column.description}`) } console.timeEnd('showColumnInfo') // 4757.181ms}showColumnInfo()
循环中的并行
const showColumnInfo = async() => { console.time('showColumnInfo') const names = ['qianduanzhidian', 'FrontendMagazine'] const promises = names.map(x => getZhihuColumn(x)) for (const promise of promises) { const column = await promise console.log(`name:${column.name}`) console.log(`description:${column.description}`) } console.timeEnd('showColumnInfo') // 2615.484ms}showColumnInfo()
阅读全文
0 0
- await-async
- async await
- async/await
- async&await
- Async/Await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- Async/await
- [c#]: async and await
- Async Redis await BookSleeve
- Async 和 Await 技术
- cenos系统python项目报错mysql Access denied for user root@localhost错误解决方法
- 深夜博客
- C++标准库中string类型与数值类型之间的转换
- Spring声明式事务注意点,以及不生效情况
- 小游戏--三子棋(任意几子棋)
- async/await
- System.arraycopy()和Arrays.copyOf()的区别
- ActiveMQ(1)-初探
- tp3.2笑脸改版例子1
- CCF-201709-1-打酱油
- Unicode与UTF-8的区别与联系
- Python内建函数—isinstance()函数
- 用户输入行数,控制输出形成下三角,并保证每行的数值不同
- Windows程序设计(5):移动窗口、调整窗口大小