async function getTitle(url) { let response = await fetch(url); let html = await response.text(); return html.match(/<title>([\s\S]+)<\/title>/i)[1]; } for(let i=0;i<2;i++){ let urls = `https://tc39.github.io/ecma262/` !async function(){ let result = await getTitle(urls).then(function(title){ console.log('22222',title,i) return title }) console.log(result) }() }```實際運行結果是,同時發生了兩個請求,然后等待請求接過返回后,打印結果想期望是請求完第一個接口,并且成功返回后,再請求第二個接口請求
for循環中的async問題
繁星coding
2019-03-29 22:18:10