-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
Description
- 循环+promise
https://www.html.cn/web/javascript/14139.html
https://segmentfault.com/a/1190000014598785
https://cary.im/2019/04/02/ES6%E5%BE%AA%E7%8E%AF%E6%96%B9%E6%B3%95%E7%90%86%E8%A7%A3/
function fn(i) {
return new Promise((res, rej) => {
setTimeout(() => {
console.log('hi', i);
res();
}, 1000);
})
}
(async function() {
for (let i = 0; i < 4; i++) {
await fn(i);
}
})()
Promise.all([1, 2, 3, 4].map(i => fn(i)))
.then(results => {
console.log('results: ', results);
})
Promise.all([1, 2, 3, 4].map(i => fn(i)))
.then(results => {
console.log('results: ', results);
})
(async function() {
[1, 2, 3, 4].map(async i => await fn(i))
})()
[1, 2, 3, 4].forEach(async i => await fn(i))
- 循环引用
报错 Uncaught (in promise) TypeError: Chaining cycle detected for promise #
https://segmentfault.com/q/1010000022027349/a-1020000022029274
Reactions are currently unavailable